aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/aerc-config.5.scd2
-rw-r--r--lib/format/format.go27
-rw-r--r--widgets/dirlist.go4
3 files changed, 33 insertions, 0 deletions
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index 6f5c50a7..314aa572 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -187,6 +187,8 @@ These options are configured in the *[ui]* section of aerc.conf.
: literal %
| %n
: directory name
+| %N
+: compacted directory name
| %r
: recent/unseen/total message count
| %>X
diff --git a/lib/format/format.go b/lib/format/format.go
index 59b5c479..ca90ac4a 100644
--- a/lib/format/format.go
+++ b/lib/format/format.go
@@ -39,6 +39,33 @@ func FormatAddresses(l []*mail.Address) string {
return strings.Join(formatted, ", ")
}
+// CompactPath reduces a directory path into a compact form. The directory
+// name will be split with the provided separator and each part will be reduced
+// to the first letter in its name: INBOX/01_WORK/PROJECT will become
+// I/W/PROJECT.
+func CompactPath(name string, sep rune) (compact string) {
+ parts := strings.Split(name, string(sep))
+ for i, part := range parts {
+ if i == len(parts)-1 {
+ compact += part
+ } else {
+ if len(part) != 0 {
+ r := part[0]
+ for i := 0; i < len(part)-1; i++ {
+ if unicode.IsLetter(rune(part[i])) {
+ r = part[i]
+ break
+ }
+ }
+ compact += fmt.Sprintf("%c%c", r, sep)
+ } else {
+ compact += fmt.Sprintf("%c", sep)
+ }
+ }
+ }
+ return
+}
+
type Ctx struct {
FromAddress string
AccountName string
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index 5ddb1362..412ed06c 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -15,6 +15,7 @@ import (
"git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
+ "git.sr.ht/~rjarry/aerc/lib/format"
libsort "git.sr.ht/~rjarry/aerc/lib/sort"
"git.sr.ht/~rjarry/aerc/lib/ui"
"git.sr.ht/~rjarry/aerc/logging"
@@ -206,6 +207,9 @@ func (dirlist *DirectoryList) getDirString(name string, width int, recentUnseen
if percent {
rightJustify = true
}
+ case 'N':
+ name = format.CompactPath(name, os.PathSeparator)
+ fallthrough
case 'n':
if percent {
if rightJustify {