diff --git a/src/environment/shell.go b/src/environment/shell.go index fb2815d1..185efac1 100644 --- a/src/environment/shell.go +++ b/src/environment/shell.go @@ -726,8 +726,9 @@ func (env *ShellEnvironment) TemplateCache() *TemplateCache { val := splitted[1:] tmplCache.Env[key] = strings.Join(val, separator) } - tmplCache.PWD = env.Pwd() - tmplCache.Folder = Base(env, tmplCache.PWD) + pwd := env.Pwd() + tmplCache.PWD = strings.Replace(pwd, env.Home(), "~", 1) + tmplCache.Folder = Base(env, pwd) tmplCache.UserName = env.User() if host, err := env.Host(); err == nil { tmplCache.HostName = host diff --git a/src/segments/git.go b/src/segments/git.go index f1ac3407..1a2fe35d 100644 --- a/src/segments/git.go +++ b/src/segments/git.go @@ -160,7 +160,8 @@ func (g *Git) shouldDisplay() bool { } // convert the worktree file path to a windows one when in wsl 2 shared folder - g.Dir = strings.TrimSuffix(g.convertToWindowsPath(gitdir.Path), "/.git") + dir := strings.Replace(gitdir.Path, g.env.Home(), "~", 1) // align with template PWD + g.Dir = strings.TrimSuffix(g.convertToWindowsPath(dir), "/.git") if !gitdir.IsDir { return g.hasWorktree(gitdir) @@ -168,7 +169,7 @@ func (g *Git) shouldDisplay() bool { g.workingDir = gitdir.Path g.rootDir = gitdir.Path - g.realDir = g.Dir + g.realDir = strings.TrimSuffix(g.convertToWindowsPath(gitdir.Path), "/.git") return true } diff --git a/src/segments/git_test.go b/src/segments/git_test.go index 5afc2564..adbf87ee 100644 --- a/src/segments/git_test.go +++ b/src/segments/git_test.go @@ -47,6 +47,7 @@ func TestEnabledInWorkingDirectory(t *testing.T) { env.On("IsWsl").Return(false) env.On("HasParentFilePath", ".git").Return(fileInfo, nil) env.On("PathSeparator").Return("/") + env.On("Home").Return("/Users/posh") g := &Git{ scm: scm{ env: env,