mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
parent
56ae9e6fda
commit
7c7ce069e0
|
@ -355,11 +355,13 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enableMappedLocations := pt.props.GetBool(MappedLocationsEnabled, true)
|
||||||
|
|
||||||
|
// built-in mapped locations, can be disabled
|
||||||
mappedLocations := map[string]string{}
|
mappedLocations := map[string]string{}
|
||||||
if pt.props.GetBool(MappedLocationsEnabled, true) {
|
if enableMappedLocations {
|
||||||
mappedLocations["hkcu:"] = pt.props.GetString(WindowsRegistryIcon, "\uF013")
|
mappedLocations["hkcu:"] = pt.props.GetString(WindowsRegistryIcon, "\uF013")
|
||||||
mappedLocations["hklm:"] = pt.props.GetString(WindowsRegistryIcon, "\uF013")
|
mappedLocations["hklm:"] = pt.props.GetString(WindowsRegistryIcon, "\uF013")
|
||||||
mappedLocations[pt.normalize(pt.env.Home())] = pt.props.GetString(HomeIcon, "~")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge custom locations with mapped locations
|
// merge custom locations with mapped locations
|
||||||
|
@ -387,6 +389,12 @@ func (pt *Path) replaceMappedLocations(pwd string) string {
|
||||||
return value + pwd[len(key):]
|
return value + pwd[len(key):]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// treat this as a built-in mapped location
|
||||||
|
if enableMappedLocations && pt.inHomeDir(pwd) {
|
||||||
|
return pt.props.GetString(HomeIcon, "~") + pwd[len(pt.env.Home()):]
|
||||||
|
}
|
||||||
|
|
||||||
return pwd
|
return pwd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,7 +413,14 @@ func (pt *Path) replaceFolderSeparators(pwd string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pt *Path) inHomeDir(pwd string) bool {
|
func (pt *Path) inHomeDir(pwd string) bool {
|
||||||
return strings.HasPrefix(pwd, pt.env.Home())
|
home := pt.env.Home()
|
||||||
|
if home == pwd {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if !strings.HasSuffix(home, pt.env.PathSeparator()) {
|
||||||
|
home += pt.env.PathSeparator()
|
||||||
|
}
|
||||||
|
return strings.HasPrefix(pwd, home)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pt *Path) rootLocation() string {
|
func (pt *Path) rootLocation() string {
|
||||||
|
|
|
@ -46,30 +46,39 @@ const (
|
||||||
levelDir = "/level"
|
levelDir = "/level"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsInHomeDirTrue(t *testing.T) {
|
func TestIsInHomeDir(t *testing.T) {
|
||||||
home := homeBill
|
cases := []struct {
|
||||||
env := new(mock.MockedEnvironment)
|
Case string
|
||||||
env.On("Home").Return(home)
|
Expected bool
|
||||||
path := &Path{
|
Dir string
|
||||||
env: env,
|
}{
|
||||||
|
{
|
||||||
|
Case: "in home dir",
|
||||||
|
Expected: true,
|
||||||
|
Dir: homeBill,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "in home dir subdirectory",
|
||||||
|
Expected: true,
|
||||||
|
Dir: homeBill + "/go/src/github.com/JanDeDobbeleer/oh-my-posh",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "in similar home dir but not really",
|
||||||
|
Expected: false,
|
||||||
|
Dir: "/home/bill-test",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
got := path.inHomeDir(home)
|
for _, tc := range cases {
|
||||||
assert.True(t, got)
|
home := homeBill
|
||||||
}
|
env := new(mock.MockedEnvironment)
|
||||||
|
env.On("Home").Return(home)
|
||||||
func TestIsInHomeDirLevelTrue(t *testing.T) {
|
env.On("PathSeparator").Return("/")
|
||||||
home := homeBill
|
path := &Path{
|
||||||
pwd := home
|
env: env,
|
||||||
for i := 0; i < 99; i++ {
|
}
|
||||||
pwd += levelDir
|
got := path.inHomeDir(tc.Dir)
|
||||||
|
assert.Equal(t, tc.Expected, got, tc.Case)
|
||||||
}
|
}
|
||||||
env := new(mock.MockedEnvironment)
|
|
||||||
env.On("Home").Return(home)
|
|
||||||
path := &Path{
|
|
||||||
env: env,
|
|
||||||
}
|
|
||||||
got := path.inHomeDir(pwd)
|
|
||||||
assert.True(t, got)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRootLocationHome(t *testing.T) {
|
func TestRootLocationHome(t *testing.T) {
|
||||||
|
@ -149,17 +158,6 @@ func TestParent(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsInHomeDirFalse(t *testing.T) {
|
|
||||||
home := homeBill
|
|
||||||
env := new(mock.MockedEnvironment)
|
|
||||||
env.On("Home").Return(home)
|
|
||||||
path := &Path{
|
|
||||||
env: env,
|
|
||||||
}
|
|
||||||
got := path.inHomeDir("/usr/error")
|
|
||||||
assert.False(t, got)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPathDepthMultipleLevelsDeep(t *testing.T) {
|
func TestPathDepthMultipleLevelsDeep(t *testing.T) {
|
||||||
pwd := "/usr"
|
pwd := "/usr"
|
||||||
for i := 0; i < 99; i++ {
|
for i := 0; i < 99; i++ {
|
||||||
|
@ -865,6 +863,7 @@ func TestGetPwd(t *testing.T) {
|
||||||
Pswd string
|
Pswd string
|
||||||
Expected string
|
Expected string
|
||||||
}{
|
}{
|
||||||
|
{MappedLocationsEnabled: true, Pwd: "/usr/home-test", Expected: "/usr/home-test"},
|
||||||
{MappedLocationsEnabled: true, Pwd: "", Expected: ""},
|
{MappedLocationsEnabled: true, Pwd: "", Expected: ""},
|
||||||
{MappedLocationsEnabled: true, Pwd: "/usr", Expected: "/usr"},
|
{MappedLocationsEnabled: true, Pwd: "/usr", Expected: "/usr"},
|
||||||
{MappedLocationsEnabled: true, Pwd: "/usr/home", Expected: "~"},
|
{MappedLocationsEnabled: true, Pwd: "/usr/home", Expected: "~"},
|
||||||
|
|
Loading…
Reference in a new issue