Skip to content

Commit da1bb46

Browse files
aexvirJanDeDobbeleer
authored andcommitted
fix(path): correctly handle replaced paths for letter style
1 parent 06e5a24 commit da1bb46

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

docs/docs/segment-path.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,10 @@ for the folders to display is governed by the `mixed_threshold` property.
111111

112112
### Letter
113113

114-
Works like `Full`, but will write every subfolder name using the first letter only.
114+
Works like `Full`, but will write every subfolder name using the first letter only, except when the folder name
115+
starts with a symbol or icon.
116+
117+
- `folder` will be shortened to `f`
118+
- `.config` will be shortened to `.c`
119+
- `__pycache__` will be shortened to `__p`
120+
- `➼ folder` will be shortened to `➼ f`

src/segment_path.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,20 @@ func (pt *path) getLetterPath() string {
155155
if len(folder) == 0 {
156156
continue
157157
}
158-
var letter string
159-
if strings.HasPrefix(folder, ".") && len(folder) > 1 {
160-
letter = folder[0:2]
161-
} else {
162-
letter = folder[0:1]
158+
159+
// check if there is at least a letter we can use
160+
matches := findNamedRegexMatch(`(?P<letter>[\p{L}0-9]).*`, folder)
161+
162+
if matches == nil || matches["letter"] == "" {
163+
// no letter found, keep the folder unchanged
164+
buffer.WriteString(fmt.Sprintf("%s%s", folder, separator))
165+
continue
163166
}
167+
168+
letter := matches["letter"]
169+
// handle non-letter characters before the first found letter
170+
letter = folder[0:strings.Index(folder, letter)] + letter
171+
164172
buffer.WriteString(fmt.Sprintf("%s%s", letter, separator))
165173
}
166174
buffer.WriteString(splitted[len(splitted)-1])

src/segment_path_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,13 @@ func TestAgnosterPathStyles(t *testing.T) {
366366
{Style: Letter, Expected: "u > b > a > w > man", HomePath: "/usr/home", Pwd: "/usr/burp/ab/whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
367367
{Style: Letter, Expected: "u > .b > a > w > man", HomePath: "/usr/home", Pwd: "/usr/.burp/ab/whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
368368
{Style: Letter, Expected: "u > .b > a > .w > man", HomePath: "/usr/home", Pwd: "/usr/.burp/ab/.whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
369+
{Style: Letter, Expected: "u > .b > a > ._w > man", HomePath: "/usr/home", Pwd: "/usr/.burp/ab/._whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
370+
{Style: Letter, Expected: "u > .ä > ū > .w > man", HomePath: "/usr/home", Pwd: "/usr/.äufbau/ūmgebung/.whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
371+
{Style: Letter, Expected: "u > .b > 1 > .w > man", HomePath: "/usr/home", Pwd: "/usr/.burp/12345/.whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
372+
{Style: Letter, Expected: "u > .b > 1 > .w > man", HomePath: "/usr/home", Pwd: "/usr/.burp/12345abc/.whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
373+
{Style: Letter, Expected: "u > .b > __p > .w > man", HomePath: "/usr/home", Pwd: "/usr/.burp/__pycache__/.whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
374+
{Style: Letter, Expected: "➼ > .w > man", HomePath: "/usr/home", Pwd: "➼/.whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
375+
{Style: Letter, Expected: "➼ s > .w > man", HomePath: "/usr/home", Pwd: "➼ something/.whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
369376
}
370377
for _, tc := range cases {
371378
env := new(MockedEnvironment)

0 commit comments

Comments
 (0)