statusline-format: add %p placeholder for current path

Allow showing the current working directory in the statusline via
[statusline] render-format=%p, which is useful if the user changes
directories often.

Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Bence Ferdinandy 2022-09-17 23:26:35 +02:00 committed by Robin Jarry
parent f414db7858
commit 74fd5d1119
3 changed files with 14 additions and 0 deletions

View file

@ -60,6 +60,7 @@ func (ChangeDirectory) Execute(aerc *widgets.Aerc, args []string) error {
}
if err := os.Chdir(target); err == nil {
previousDir = cwd
aerc.UpdateStatus()
}
return err
}

View file

@ -376,6 +376,8 @@ These options are configured in the *[statusline]* section of aerc.conf.
: active directory name
| %c
: connection state
| %p
: current path
| %m
: mute statusline and show only push notifications
| %S

View file

@ -3,6 +3,7 @@ package statusline
import (
"errors"
"fmt"
"os"
"strings"
"unicode"
@ -171,6 +172,16 @@ func parseStatuslineFormat(format string, texter Texter, r renderParams) (string
}
retval = append(retval, 's')
args = append(args, strings.Join(tray, r.sep))
case 'p':
path, err := os.Getwd()
if err == nil {
home, _ := os.UserHomeDir()
if strings.HasPrefix(path, home) {
path = strings.Replace(path, home, "~", 1)
}
retval = append(retval, 's')
args = append(args, path)
}
default:
// Just ignore it and print as is
// so %k in index format becomes %%k to Printf