diff --git a/src/segments/path.go b/src/segments/path.go index ad49dbdf..64565370 100644 --- a/src/segments/path.go +++ b/src/segments/path.go @@ -249,7 +249,10 @@ func (pt *Path) getAgnosterPath() string { for i := 1; i < n; i++ { elements = append(elements, folderIcon) } - elements = append(elements, splitted[n-1]) + + if len(splitted) > 0 { + elements = append(elements, splitted[n-1]) + } return pt.colorizePath(pt.root, elements) } @@ -299,7 +302,10 @@ func (pt *Path) getLetterPath() string { letter := pt.getRelevantLetter(splitted[i]) elements = append(elements, letter) } - elements = append(elements, splitted[n-1]) + + if len(splitted) > 0 { + elements = append(elements, splitted[n-1]) + } return pt.colorizePath(pt.root, elements) } @@ -349,7 +355,10 @@ func (pt *Path) getUniqueLettersPath(maxWidth int) string { } } } - elements = append(elements, splitted[n-1]) + + if len(elements) > 0 { + elements = append(elements, splitted[n-1]) + } return pt.colorizePath(pt.root, elements) } @@ -592,6 +601,10 @@ func (pt *Path) colorizePath(root string, elements []string) string { return fmt.Sprintf("<%s>%s", cycle[0], element) } + if len(elements) == 0 { + return colorizeElement(root) + } + colorizeSeparator := func() string { if skipColorize || !colorSeparator { return folderSeparator diff --git a/src/segments/path_test.go b/src/segments/path_test.go index dc6e048e..e5701e55 100644 --- a/src/segments/path_test.go +++ b/src/segments/path_test.go @@ -198,6 +198,14 @@ func TestAgnosterPathStyles(t *testing.T) { PathSeparator: "\\", FolderSeparatorIcon: " > ", }, + { + Style: Unique, + Expected: "a", + HomePath: homeDir, + Pwd: "/ab", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + }, { Style: Powerlevel, @@ -350,6 +358,14 @@ func TestAgnosterPathStyles(t *testing.T) { PathSeparator: "\\", FolderSeparatorIcon: " > ", }, + { + Style: Letter, + Expected: "w", + HomePath: homeDir, + Pwd: "/whatever", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + }, { Style: Mixed, @@ -1092,6 +1108,13 @@ func TestAgnosterPath(t *testing.T) { Cycle: []string{"blue", "yellow"}, ColorSeparator: true, }, + { + Case: "Unix one level", + Expected: "mnt", + Home: homeDir, + PWD: "/mnt", + PathSeparator: "/", + }, } for _, tc := range cases {