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"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -78,9 +79,20 @@ func (pt *path) getShortPath() string {
|
||||||
mappedLocations[key] = val
|
mappedLocations[key] = val
|
||||||
}
|
}
|
||||||
|
|
||||||
for location, value := range mappedLocations {
|
// sort map keys in reverse order
|
||||||
if strings.HasPrefix(pwd, location) {
|
// fixes case when a subfoder and its parent are mapped
|
||||||
return strings.Replace(pwd, location, value, 1)
|
// 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
|
return pwd
|
||||||
|
|
Loading…
Reference in a new issue