mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
fix: sort mapped locations to solve the folder/subfolder issue
This commit is contained in:
parent
2a54724a75
commit
c0fd060c89
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -78,9 +79,20 @@ func (pt *path) getShortPath() string {
|
|||
mappedLocations[key] = val
|
||||
}
|
||||
|
||||
for location, value := range mappedLocations {
|
||||
if strings.HasPrefix(pwd, location) {
|
||||
return strings.Replace(pwd, location, value, 1)
|
||||
// sort map keys in reverse order
|
||||
// fixes case when a subfoder and its parent are mapped
|
||||
// ex /users/test and /users/test/dev
|
||||
keys := make([]string, len(mappedLocations))
|
||||
i := 0
|
||||
for k := range mappedLocations {
|
||||
keys[i] = k
|
||||
i++
|
||||
}
|
||||
sort.Sort(sort.Reverse(sort.StringSlice(keys)))
|
||||
|
||||
for _, value := range keys {
|
||||
if strings.HasPrefix(pwd, value) {
|
||||
return strings.Replace(pwd, value, mappedLocations[value], 1)
|
||||
}
|
||||
}
|
||||
return pwd
|
||||
|
|
Loading…
Reference in a new issue