fix: adjust mapped_locations_enabled for hardcoded only

resolves #854
This commit is contained in:
Jan De Dobbeleer 2021-07-24 19:49:01 +02:00 committed by Jan De Dobbeleer
parent 0813ef5af6
commit 40238b8226
3 changed files with 12 additions and 11 deletions

View file

@ -47,8 +47,8 @@ locations before doing a replacement.
- mapped_locations_enabled: `boolean` - replace known locations in the path with the replacements before applying the - mapped_locations_enabled: `boolean` - replace known locations in the path with the replacements before applying the
style. defaults to `true` style. defaults to `true`
- mapped_locations: `map[string]string` - custom glyph/text for specific paths (only when `mapped_locations_enabled` - mapped_locations: `map[string]string` - custom glyph/text for specific paths. Works regardless of the `mapped_locations_enabled`
is set to `true`) setting.
For example, to swap out `C:\Users\Leet\GitHub` with a GitHub icon, you can do the following: For example, to swap out `C:\Users\Leet\GitHub` with a GitHub icon, you can do the following:

View file

@ -200,9 +200,7 @@ func (pt *path) getPwd() string {
if pwd == "" { if pwd == "" {
pwd = pt.env.getcwd() pwd = pt.env.getcwd()
} }
if pt.props.getBool(MappedLocationsEnabled, true) { pwd = pt.replaceMappedLocations(pwd)
pwd = pt.replaceMappedLocations(pwd)
}
return pwd return pwd
} }
@ -211,10 +209,11 @@ func (pt *path) replaceMappedLocations(pwd string) string {
pwd = strings.Replace(pwd, "Microsoft.PowerShell.Core\\FileSystem::", "", 1) pwd = strings.Replace(pwd, "Microsoft.PowerShell.Core\\FileSystem::", "", 1)
} }
mappedLocations := map[string]string{ mappedLocations := map[string]string{}
"HKCU:": pt.props.getString(WindowsRegistryIcon, "\uF013"), if pt.props.getBool(MappedLocationsEnabled, true) {
"HKLM:": pt.props.getString(WindowsRegistryIcon, "\uF013"), mappedLocations["HKCU:"] = pt.props.getString(WindowsRegistryIcon, "\uF013")
pt.env.homeDir(): pt.props.getString(HomeIcon, "~"), mappedLocations["HKLM:"] = pt.props.getString(WindowsRegistryIcon, "\uF013")
mappedLocations[pt.env.homeDir()] = pt.props.getString(HomeIcon, "~")
} }
// merge custom locations with mapped locations // merge custom locations with mapped locations

View file

@ -571,10 +571,12 @@ func TestGetPwd(t *testing.T) {
{MappedLocationsEnabled: false, Pwd: "", Expected: ""}, {MappedLocationsEnabled: false, Pwd: "", Expected: ""},
{MappedLocationsEnabled: false, Pwd: "/usr/home/abc", Expected: "/usr/home/abc"}, {MappedLocationsEnabled: false, Pwd: "/usr/home/abc", Expected: "/usr/home/abc"},
{MappedLocationsEnabled: false, Pwd: "/a/b/c/d/e/f/g", Expected: "/a/b/c/d/e/f/g"}, {MappedLocationsEnabled: false, Pwd: "/a/b/c/d/e/f/g", Expected: "#/e/f/g"},
{MappedLocationsEnabled: false, Pwd: "/usr/home/c/d/e/f/g", Expected: "/usr/home/c/d/e/f/g"},
{MappedLocationsEnabled: true, Pwd: "/usr/home/c/d/e/f/g", Expected: "~/c/d/e/f/g"},
{MappedLocationsEnabled: true, Pwd: "/w/d/x/w", Pswd: "/z/y/x/w", Expected: "/z/y/x/w"}, {MappedLocationsEnabled: true, Pwd: "/w/d/x/w", Pswd: "/z/y/x/w", Expected: "/z/y/x/w"},
{MappedLocationsEnabled: false, Pwd: "/f/g/k/d/e/f/g", Pswd: "/a/b/c/d/e/f/g", Expected: "/a/b/c/d/e/f/g"}, {MappedLocationsEnabled: false, Pwd: "/f/g/k/d/e/f/g", Pswd: "/a/b/c/d/e/f/g", Expected: "#/e/f/g"},
} }
for _, tc := range cases { for _, tc := range cases {