dirlist: add format specifier to compact folder name
Add the format specifier %N to the dirlist-format to display compacted folder names. A folder such as INBOX/WORK/PROJECT will be compacted to I/W/PROJECT in the directoy list. Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
parent
8f976af17b
commit
e1ae7b80cc
3 changed files with 33 additions and 0 deletions
|
@ -187,6 +187,8 @@ These options are configured in the *[ui]* section of aerc.conf.
|
||||||
: literal %
|
: literal %
|
||||||
| %n
|
| %n
|
||||||
: directory name
|
: directory name
|
||||||
|
| %N
|
||||||
|
: compacted directory name
|
||||||
| %r
|
| %r
|
||||||
: recent/unseen/total message count
|
: recent/unseen/total message count
|
||||||
| %>X
|
| %>X
|
||||||
|
|
|
@ -39,6 +39,33 @@ func FormatAddresses(l []*mail.Address) string {
|
||||||
return strings.Join(formatted, ", ")
|
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 {
|
type Ctx struct {
|
||||||
FromAddress string
|
FromAddress string
|
||||||
AccountName string
|
AccountName string
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
|
|
||||||
"git.sr.ht/~rjarry/aerc/config"
|
"git.sr.ht/~rjarry/aerc/config"
|
||||||
"git.sr.ht/~rjarry/aerc/lib"
|
"git.sr.ht/~rjarry/aerc/lib"
|
||||||
|
"git.sr.ht/~rjarry/aerc/lib/format"
|
||||||
libsort "git.sr.ht/~rjarry/aerc/lib/sort"
|
libsort "git.sr.ht/~rjarry/aerc/lib/sort"
|
||||||
"git.sr.ht/~rjarry/aerc/lib/ui"
|
"git.sr.ht/~rjarry/aerc/lib/ui"
|
||||||
"git.sr.ht/~rjarry/aerc/logging"
|
"git.sr.ht/~rjarry/aerc/logging"
|
||||||
|
@ -206,6 +207,9 @@ func (dirlist *DirectoryList) getDirString(name string, width int, recentUnseen
|
||||||
if percent {
|
if percent {
|
||||||
rightJustify = true
|
rightJustify = true
|
||||||
}
|
}
|
||||||
|
case 'N':
|
||||||
|
name = format.CompactPath(name, os.PathSeparator)
|
||||||
|
fallthrough
|
||||||
case 'n':
|
case 'n':
|
||||||
if percent {
|
if percent {
|
||||||
if rightJustify {
|
if rightJustify {
|
||||||
|
|
Loading…
Reference in a new issue