From 7b89126e04597e20b30288e993ff6fa9bb47c254 Mon Sep 17 00:00:00 2001 From: arolle <1167984+arolle@users.noreply.github.com> Date: Mon, 7 Oct 2019 21:30:52 +0200 Subject: [PATCH] Correct abbreviation of the home directory (#241) The path has to start with the home directory to be shortened to `~`. Previously a user named `user` would see `/media/backup~/files` when browsing `/media/backup/home/user/files`. --- ui.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ui.go b/ui.go index cf9ab41..7dc753b 100644 --- a/ui.go +++ b/ui.go @@ -557,9 +557,11 @@ func (ui *ui) loadFileInfo(nav *nav) { func (ui *ui) drawPromptLine(nav *nav) { fg, bg := termbox.ColorDefault, termbox.ColorDefault - dir := nav.currDir() - - pwd := strings.Replace(dir.path, gUser.HomeDir, "~", -1) + pwd := nav.currDir().path + nohome := strings.TrimPrefix(pwd, gUser.HomeDir) + if len(nohome) < len(pwd) { + pwd = "~/" + nohome + } pwd = filepath.Clean(pwd) var fname string