expand '%w' in 'promptfmt' with a trailing slash

Related #421
This commit is contained in:
Gokcehan committed 2020-07-20 00:19:42 +03:00
1 parent 3b49e1a2b6
commit f8daa60b31
5 files changed
+18 -8

No files matched your search

+13 -4
View File
@@ -574,12 +574,19 @@ func (ui *ui) drawPromptLine(nav *nav) {
fg, bg := termbox.ColorDefault, termbox.ColorDefault
pwd := nav.currDir().path
nohome := strings.TrimPrefix(pwd, gUser.HomeDir)
if len(nohome) < len(pwd) {
pwd = "~/" + nohome
if strings.HasPrefix(pwd, gUser.HomeDir) {
pwd = filepath.Join("~", strings.TrimPrefix(pwd, gUser.HomeDir))
}
pwd = filepath.Clean(pwd)
sep := string(filepath.Separator)
if !strings.HasSuffix(pwd, sep) {
pwd += sep
}
var fname string
curr, err := nav.currFile()
if err == nil {
@@ -593,9 +600,11 @@ func (ui *ui) drawPromptLine(nav *nav) {
prompt = strings.Replace(prompt, "%f", fname, -1)
if printLength(strings.Replace(prompt, "%w", pwd, -1)) > ui.promptWin.w {
sep := string(filepath.Separator)
names := strings.Split(pwd, sep)
for i := range names {
if names[i] == "" {
continue
}
r, _ := utf8.DecodeRuneInString(names[i])
names[i] = string(r)
if printLength(strings.Replace(prompt, "%w", strings.Join(names, sep), -1)) <= ui.promptWin.w {