From 6bc0f888c23c63c10ab48ab97d86b2b34f269df0 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Fri, 14 Oct 2022 07:45:54 +0200 Subject: [PATCH] fix(path): correct root on full style resolves #2939 --- src/segments/path.go | 5 +++-- src/segments/path_test.go | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/segments/path.go b/src/segments/path.go index 6dd48276..c01c2759 100644 --- a/src/segments/path.go +++ b/src/segments/path.go @@ -364,8 +364,9 @@ func (pt *Path) getAgnosterShortPath() string { func (pt *Path) getFullPath() string { rel := pt.relative - if pt.root != pt.env.PathSeparator() { - rel = pt.env.PathSeparator() + rel + pathSeparator := pt.env.PathSeparator() + if pt.root != pathSeparator && !strings.HasSuffix(pt.root, pathSeparator) { + rel = pathSeparator + rel } path := pt.replaceFolderSeparators(rel) return pt.root + path diff --git a/src/segments/path_test.go b/src/segments/path_test.go index 370cd2d2..1a08e9c2 100644 --- a/src/segments/path_test.go +++ b/src/segments/path_test.go @@ -747,6 +747,7 @@ func TestFullAndFolderPath(t *testing.T) { {Style: Folder, FolderSeparatorIcon: "\\", Pwd: homeDirWindows, Expected: "~", PathSeparator: "\\", GOOS: environment.WINDOWS}, {Style: Full, FolderSeparatorIcon: "\\", Pwd: homeDirWindows, Expected: "~", PathSeparator: "\\", GOOS: environment.WINDOWS}, {Style: Full, FolderSeparatorIcon: "\\", Pwd: homeDirWindows + "\\abc", Expected: "~\\abc", PathSeparator: "\\", GOOS: environment.WINDOWS}, + {Style: Full, FolderSeparatorIcon: "\\", Pwd: "C:\\Users\\posh", Expected: "C:\\Users\\posh", PathSeparator: "\\", GOOS: environment.WINDOWS}, // StackCountEnabled=true and StackCount=2 {Style: Full, FolderSeparatorIcon: "|", Pwd: "/", StackCount: 2, Expected: "2 /"},