aboutsummaryrefslogtreecommitdiffstats
path: root/lib/statusline/renderer.go
diff options
context:
space:
mode:
authorBence Ferdinandy <bence@ferdinandy.com>2022-09-17 23:26:35 +0200
committerRobin Jarry <robin@jarry.cc>2022-09-19 21:25:10 +0200
commit74fd5d11194d866a261a8f64d77c78a19ff2b174 (patch)
treeb4e4fcaa2d59c0bcf2606989689b0370ba0c897b /lib/statusline/renderer.go
parentf414db7858c033c6b7845897c9cde35beff22c87 (diff)
downloadaerc-74fd5d11194d866a261a8f64d77c78a19ff2b174.tar.gz
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>
Diffstat (limited to 'lib/statusline/renderer.go')
-rw-r--r--lib/statusline/renderer.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/statusline/renderer.go b/lib/statusline/renderer.go
index 26c95c24..f128e6a2 100644
--- a/lib/statusline/renderer.go
+++ b/lib/statusline/renderer.go
@@ -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