mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-26 19:39:39 -08:00
fix(path): correctly handle replaced paths for letter style
This commit is contained in:
parent
06e5a24a0b
commit
da1bb46a94
|
@ -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`
|
||||
|
|
|
@ -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<letter>[\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])
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue