diff --git a/docs/docs/segment-path.md b/docs/docs/segment-path.md index 3c96b31f23a6..5b3faa3640c5 100644 --- a/docs/docs/segment-path.md +++ b/docs/docs/segment-path.md @@ -111,4 +111,10 @@ for the folders to display is governed by the `mixed_threshold` property. ### Letter -Works like `Full`, but will write every subfolder name using the first letter only. +Works like `Full`, but will write every subfolder name using the first letter only, except when the folder name +starts with a symbol or icon. + +- `folder` will be shortened to `f` +- `.config` will be shortened to `.c` +- `__pycache__` will be shortened to `__p` +- `➼ folder` will be shortened to `➼ f` diff --git a/src/segment_path.go b/src/segment_path.go index 1c8fe6a848e0..a7da427e0d54 100644 --- a/src/segment_path.go +++ b/src/segment_path.go @@ -155,12 +155,20 @@ func (pt *path) getLetterPath() string { if len(folder) == 0 { continue } - var letter string - if strings.HasPrefix(folder, ".") && len(folder) > 1 { - letter = folder[0:2] - } else { - letter = folder[0:1] + + // check if there is at least a letter we can use + matches := findNamedRegexMatch(`(?P[\p{L}0-9]).*`, folder) + + if matches == nil || matches["letter"] == "" { + // no letter found, keep the folder unchanged + buffer.WriteString(fmt.Sprintf("%s%s", folder, separator)) + continue } + + letter := matches["letter"] + // handle non-letter characters before the first found letter + letter = folder[0:strings.Index(folder, letter)] + letter + buffer.WriteString(fmt.Sprintf("%s%s", letter, separator)) } buffer.WriteString(splitted[len(splitted)-1]) diff --git a/src/segment_path_test.go b/src/segment_path_test.go index b4d71d9d5946..f17f8bf84913 100644 --- a/src/segment_path_test.go +++ b/src/segment_path_test.go @@ -366,6 +366,13 @@ func TestAgnosterPathStyles(t *testing.T) { {Style: Letter, Expected: "u > b > a > w > man", HomePath: "/usr/home", Pwd: "/usr/burp/ab/whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "}, {Style: Letter, Expected: "u > .b > a > w > man", HomePath: "/usr/home", Pwd: "/usr/.burp/ab/whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "}, {Style: Letter, Expected: "u > .b > a > .w > man", HomePath: "/usr/home", Pwd: "/usr/.burp/ab/.whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "}, + {Style: Letter, Expected: "u > .b > a > ._w > man", HomePath: "/usr/home", Pwd: "/usr/.burp/ab/._whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "}, + {Style: Letter, Expected: "u > .ä > ū > .w > man", HomePath: "/usr/home", Pwd: "/usr/.äufbau/ūmgebung/.whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "}, + {Style: Letter, Expected: "u > .b > 1 > .w > man", HomePath: "/usr/home", Pwd: "/usr/.burp/12345/.whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "}, + {Style: Letter, Expected: "u > .b > 1 > .w > man", HomePath: "/usr/home", Pwd: "/usr/.burp/12345abc/.whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "}, + {Style: Letter, Expected: "u > .b > __p > .w > man", HomePath: "/usr/home", Pwd: "/usr/.burp/__pycache__/.whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "}, + {Style: Letter, Expected: "➼ > .w > man", HomePath: "/usr/home", Pwd: "➼/.whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "}, + {Style: Letter, Expected: "➼ s > .w > man", HomePath: "/usr/home", Pwd: "➼ something/.whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "}, } for _, tc := range cases { env := new(MockedEnvironment)