Skip to content

Commit

Permalink
fix(path): correctly handle replaced paths for letter style
Browse files Browse the repository at this point in the history
  • Loading branch information
aexvir authored and JanDeDobbeleer committed Oct 17, 2021
1 parent 06e5a24 commit da1bb46
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
8 changes: 7 additions & 1 deletion docs/docs/segment-path.md
Expand Up @@ -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`
18 changes: 13 additions & 5 deletions src/segment_path.go
Expand Up @@ -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])
Expand Down
7 changes: 7 additions & 0 deletions src/segment_path_test.go
Expand Up @@ -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)
Expand Down

0 comments on commit da1bb46

Please sign in to comment.