mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 20:39:40 -08:00
parent
1a5f4819e1
commit
64f64d20c0
|
@ -61,10 +61,12 @@ func (pt *path) init(props *properties, env environmentInfo) {
|
||||||
|
|
||||||
func (pt *path) getShortPath() string {
|
func (pt *path) getShortPath() string {
|
||||||
pwd := pt.env.getcwd()
|
pwd := pt.env.getcwd()
|
||||||
|
if strings.HasPrefix(pwd, "Microsoft.PowerShell.Core\\FileSystem::") {
|
||||||
|
pwd = strings.Replace(pwd, "Microsoft.PowerShell.Core\\FileSystem::", "", 1)
|
||||||
|
}
|
||||||
mappedLocations := map[string]string{
|
mappedLocations := map[string]string{
|
||||||
"HKCU:": pt.props.getString(WindowsRegistryIcon, "\uE0B1"),
|
"HKCU:": pt.props.getString(WindowsRegistryIcon, "\uE0B1"),
|
||||||
"HKLM:": pt.props.getString(WindowsRegistryIcon, "\uE0B1"),
|
"HKLM:": pt.props.getString(WindowsRegistryIcon, "\uE0B1"),
|
||||||
"Microsoft.PowerShell.Core\\FileSystem::": "",
|
|
||||||
pt.env.homeDir(): pt.props.getString(HomeIcon, "~"),
|
pt.env.homeDir(): pt.props.getString(HomeIcon, "~"),
|
||||||
}
|
}
|
||||||
for location, value := range mappedLocations {
|
for location, value := range mappedLocations {
|
||||||
|
@ -76,9 +78,9 @@ func (pt *path) getShortPath() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pt *path) getAgnosterPath() string {
|
func (pt *path) getAgnosterPath() string {
|
||||||
pwd := pt.env.getcwd()
|
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
buffer.WriteString(pt.rootLocation(pwd))
|
pwd := pt.getShortPath()
|
||||||
|
buffer.WriteString(pt.rootLocation())
|
||||||
pathDepth := pt.pathDepth(pwd)
|
pathDepth := pt.pathDepth(pwd)
|
||||||
for i := 1; i < pathDepth; i++ {
|
for i := 1; i < pathDepth; i++ {
|
||||||
buffer.WriteString(fmt.Sprintf("%s%s", pt.props.getString(FolderSeparatorIcon, pt.env.getPathSeperator()), pt.props.getString(FolderIcon, "..")))
|
buffer.WriteString(fmt.Sprintf("%s%s", pt.props.getString(FolderSeparatorIcon, pt.env.getPathSeperator()), pt.props.getString(FolderIcon, "..")))
|
||||||
|
@ -90,7 +92,7 @@ func (pt *path) getAgnosterPath() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pt *path) getAgnosterFullPath() string {
|
func (pt *path) getAgnosterFullPath() string {
|
||||||
pwd := pt.env.getcwd()
|
pwd := pt.getShortPath()
|
||||||
pathSeparator := pt.env.getPathSeperator()
|
pathSeparator := pt.env.getPathSeperator()
|
||||||
folderSeparator := pt.props.getString(FolderSeparatorIcon, pathSeparator)
|
folderSeparator := pt.props.getString(FolderSeparatorIcon, pathSeparator)
|
||||||
if string(pwd[0]) == pathSeparator {
|
if string(pwd[0]) == pathSeparator {
|
||||||
|
@ -103,23 +105,11 @@ func (pt *path) inHomeDir(pwd string) bool {
|
||||||
return strings.HasPrefix(pwd, pt.env.homeDir())
|
return strings.HasPrefix(pwd, pt.env.homeDir())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pt *path) rootLocation(pwd string) string {
|
func (pt *path) rootLocation() string {
|
||||||
// See https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/correcting-powershell-paths
|
pwd := pt.getShortPath()
|
||||||
if strings.HasPrefix(pwd, "Microsoft.PowerShell.Core\\FileSystem::") {
|
|
||||||
pwd = strings.Replace(pwd, "Microsoft.PowerShell.Core\\FileSystem::", "", 1)
|
|
||||||
}
|
|
||||||
if pt.inHomeDir(pwd) {
|
|
||||||
return pt.props.getString(HomeIcon, "~")
|
|
||||||
}
|
|
||||||
pwd = strings.TrimPrefix(pwd, pt.env.getPathSeperator())
|
pwd = strings.TrimPrefix(pwd, pt.env.getPathSeperator())
|
||||||
splitted := strings.Split(pwd, pt.env.getPathSeperator())
|
splitted := strings.Split(pwd, pt.env.getPathSeperator())
|
||||||
rootLocation := splitted[0]
|
rootLocation := splitted[0]
|
||||||
mappedLocations := map[string]string{
|
|
||||||
"HKCU:": pt.props.getString(WindowsRegistryIcon, "\uE0B1"),
|
|
||||||
}
|
|
||||||
if val, ok := mappedLocations[rootLocation]; ok {
|
|
||||||
return val
|
|
||||||
}
|
|
||||||
return rootLocation
|
return rootLocation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -155,13 +155,14 @@ func TestRootLocationHome(t *testing.T) {
|
||||||
}
|
}
|
||||||
home := "/home/bill/"
|
home := "/home/bill/"
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("homeDir", nil).Return("/home/bill")
|
env.On("homeDir", nil).Return(home)
|
||||||
|
env.On("getcwd", nil).Return(home)
|
||||||
env.On("getPathSeperator", nil).Return("/")
|
env.On("getPathSeperator", nil).Return("/")
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
}
|
}
|
||||||
got := path.rootLocation(home)
|
got := path.rootLocation()
|
||||||
assert.EqualValues(t, expected, got)
|
assert.EqualValues(t, expected, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,12 +172,13 @@ func TestRootLocationOutsideHome(t *testing.T) {
|
||||||
}
|
}
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("homeDir", nil).Return("/home/bill")
|
env.On("homeDir", nil).Return("/home/bill")
|
||||||
|
env.On("getcwd", nil).Return("/usr/error/what")
|
||||||
env.On("getPathSeperator", nil).Return("/")
|
env.On("getPathSeperator", nil).Return("/")
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
}
|
}
|
||||||
got := path.rootLocation("/usr/error/what")
|
got := path.rootLocation()
|
||||||
assert.EqualValues(t, "usr", got)
|
assert.EqualValues(t, "usr", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,12 +188,13 @@ func TestRootLocationWindowsDrive(t *testing.T) {
|
||||||
}
|
}
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("homeDir", nil).Return("C:\\Users\\Bill")
|
env.On("homeDir", nil).Return("C:\\Users\\Bill")
|
||||||
|
env.On("getcwd", nil).Return("C:\\Program Files\\Go")
|
||||||
env.On("getPathSeperator", nil).Return("\\")
|
env.On("getPathSeperator", nil).Return("\\")
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
}
|
}
|
||||||
got := path.rootLocation("C:\\Program Files\\Go")
|
got := path.rootLocation()
|
||||||
assert.EqualValues(t, "C:", got)
|
assert.EqualValues(t, "C:", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,12 +205,13 @@ func TestRootLocationWindowsRegistry(t *testing.T) {
|
||||||
}
|
}
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("homeDir", nil).Return("C:\\Users\\Bill")
|
env.On("homeDir", nil).Return("C:\\Users\\Bill")
|
||||||
|
env.On("getcwd", nil).Return("HKCU:\\Program Files\\Go")
|
||||||
env.On("getPathSeperator", nil).Return("\\")
|
env.On("getPathSeperator", nil).Return("\\")
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
}
|
}
|
||||||
got := path.rootLocation("HKCU:\\Program Files\\Go")
|
got := path.rootLocation()
|
||||||
assert.EqualValues(t, expected, got)
|
assert.EqualValues(t, expected, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,12 +222,13 @@ func TestRootLocationWindowsPowerShellHome(t *testing.T) {
|
||||||
}
|
}
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("homeDir", nil).Return("C:\\Users\\Bill")
|
env.On("homeDir", nil).Return("C:\\Users\\Bill")
|
||||||
|
env.On("getcwd", nil).Return("Microsoft.PowerShell.Core\\FileSystem::C:\\Users\\Bill")
|
||||||
env.On("getPathSeperator", nil).Return("\\")
|
env.On("getPathSeperator", nil).Return("\\")
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
}
|
}
|
||||||
got := path.rootLocation("Microsoft.PowerShell.Core\\FileSystem::C:\\Users\\Bill")
|
got := path.rootLocation()
|
||||||
assert.EqualValues(t, expected, got)
|
assert.EqualValues(t, expected, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,12 +238,13 @@ func TestRootLocationWindowsPowerShellOutsideHome(t *testing.T) {
|
||||||
}
|
}
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("homeDir", nil).Return("C:\\Program Files\\Go")
|
env.On("homeDir", nil).Return("C:\\Program Files\\Go")
|
||||||
|
env.On("getcwd", nil).Return("Microsoft.PowerShell.Core\\FileSystem::C:\\Users\\Bill")
|
||||||
env.On("getPathSeperator", nil).Return("\\")
|
env.On("getPathSeperator", nil).Return("\\")
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
}
|
}
|
||||||
got := path.rootLocation("Microsoft.PowerShell.Core\\FileSystem::C:\\Users\\Bill")
|
got := path.rootLocation()
|
||||||
assert.EqualValues(t, "C:", got)
|
assert.EqualValues(t, "C:", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,12 +254,13 @@ func TestRootLocationEmptyDir(t *testing.T) {
|
||||||
}
|
}
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("homeDir", nil).Return("/home/bill")
|
env.On("homeDir", nil).Return("/home/bill")
|
||||||
|
env.On("getcwd", nil).Return("")
|
||||||
env.On("getPathSeperator", nil).Return("/")
|
env.On("getPathSeperator", nil).Return("/")
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
}
|
}
|
||||||
got := path.rootLocation("")
|
got := path.rootLocation()
|
||||||
assert.EqualValues(t, "", got)
|
assert.EqualValues(t, "", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,6 +365,7 @@ func TestGetAgnosterFullPath(t *testing.T) {
|
||||||
pwd := "/usr/location/whatever"
|
pwd := "/usr/location/whatever"
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("getPathSeperator", nil).Return("/")
|
env.On("getPathSeperator", nil).Return("/")
|
||||||
|
env.On("homeDir", nil).Return("/usr/home")
|
||||||
env.On("getcwd", nil).Return(pwd)
|
env.On("getcwd", nil).Return(pwd)
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
|
|
Loading…
Reference in a new issue