display workdir in header if used

and truncate in table view
This commit is contained in:
Lilian Jónsdóttir 2024-06-30 20:01:36 -07:00
parent b60469887e
commit f859631f4e
2 changed files with 13 additions and 12 deletions

View file

@ -12,27 +12,23 @@ import (
// $PWD -> .
// workdir -> .
func UnExpand(dir, workdir string) (outdir string) {
var (
home = os.Getenv("HOME")
pwd string
err error
)
outdir = filepath.Clean(dir)
home := os.Getenv("HOME")
if workdir != "" {
outdir = strings.Replace(outdir, workdir, ".", 1)
}
pwd, err = os.Getwd()
if err == nil && home != pwd {
if pwd, err := os.Getwd(); err == nil && home != pwd {
outdir = strings.Replace(outdir, pwd, ".", 1)
} else if workdir != "" {
outdir = strings.Replace(outdir, workdir, "", 1)
}
outdir = strings.Replace(outdir, home, "~", 1)
outdir = UnEscape(outdir)
if outdir == "" {
outdir = "/"
}
return
}