mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-09 20:44:03 -08:00
parent
746a77ff02
commit
adb205fe66
|
@ -42,6 +42,7 @@ Style sets the way the path is displayed. Based on previous experience and popul
|
||||||
|
|
||||||
- agnoster
|
- agnoster
|
||||||
- agnoster_full
|
- agnoster_full
|
||||||
|
- agnoster_short
|
||||||
- short
|
- short
|
||||||
- full
|
- full
|
||||||
- folder
|
- folder
|
||||||
|
@ -56,6 +57,10 @@ inside the `$HOME` location or one of its children.
|
||||||
|
|
||||||
Renders each folder name separated by the `folder_separator_icon`.
|
Renders each folder name separated by the `folder_separator_icon`.
|
||||||
|
|
||||||
|
### Agnoster Short
|
||||||
|
|
||||||
|
When more than 1 level deep, it renders one `folder_icon` followed by the name of the current folder separated by the `folder_separator_icon`.
|
||||||
|
|
||||||
### Short
|
### Short
|
||||||
|
|
||||||
Display `$PWD` as a string, replace `$HOME` with the `home_icon` if you're inside the `$HOME` location or
|
Display `$PWD` as a string, replace `$HOME` with the `home_icon` if you're inside the `$HOME` location or
|
||||||
|
|
|
@ -26,6 +26,8 @@ const (
|
||||||
Agnoster string = "agnoster"
|
Agnoster string = "agnoster"
|
||||||
// AgnosterFull displays all the folder names with the folder_separator_icon
|
// AgnosterFull displays all the folder names with the folder_separator_icon
|
||||||
AgnosterFull string = "agnoster_full"
|
AgnosterFull string = "agnoster_full"
|
||||||
|
// AgnosterShort displays the folder names with one folder_separator_icon, regardless of depth
|
||||||
|
AgnosterShort string = "agnoster_short"
|
||||||
// Short displays a shorter path
|
// Short displays a shorter path
|
||||||
Short string = "short"
|
Short string = "short"
|
||||||
// Full displays the full path
|
// Full displays the full path
|
||||||
|
@ -46,6 +48,8 @@ func (pt *path) string() string {
|
||||||
return pt.getAgnosterPath()
|
return pt.getAgnosterPath()
|
||||||
case AgnosterFull:
|
case AgnosterFull:
|
||||||
return pt.getAgnosterFullPath()
|
return pt.getAgnosterFullPath()
|
||||||
|
case AgnosterShort:
|
||||||
|
return pt.getAgnosterShortPath()
|
||||||
case Short:
|
case Short:
|
||||||
return pt.getShortPath()
|
return pt.getShortPath()
|
||||||
case Full:
|
case Full:
|
||||||
|
@ -124,6 +128,19 @@ func (pt *path) getAgnosterFullPath() string {
|
||||||
return strings.ReplaceAll(pwd, pathSeparator, folderSeparator)
|
return strings.ReplaceAll(pwd, pathSeparator, folderSeparator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pt *path) getAgnosterShortPath() string {
|
||||||
|
pathSeparator := pt.env.getPathSeperator()
|
||||||
|
folderSeparator := pt.props.getString(FolderSeparatorIcon, pathSeparator)
|
||||||
|
folderIcon := pt.props.getString(FolderIcon, "..")
|
||||||
|
root := pt.rootLocation()
|
||||||
|
base := base(pt.env.getcwd(), pt.env)
|
||||||
|
pathDepth := pt.pathDepth(pt.getShortPath())
|
||||||
|
if pathDepth == 1 {
|
||||||
|
return fmt.Sprintf("%s%s%s", root, folderSeparator, base)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s%s%s%s%s", root, folderSeparator, folderIcon, folderSeparator, base)
|
||||||
|
}
|
||||||
|
|
||||||
func (pt *path) inHomeDir(pwd string) bool {
|
func (pt *path) inHomeDir(pwd string) bool {
|
||||||
return strings.HasPrefix(pwd, pt.env.homeDir())
|
return strings.HasPrefix(pwd, pt.env.homeDir())
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,6 +394,60 @@ func TestGetAgnosterFullPath(t *testing.T) {
|
||||||
assert.Equal(t, "usr > location > whatever", got)
|
assert.Equal(t, "usr > location > whatever", got)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetAgnosterShortPath(t *testing.T) {
|
||||||
|
pwd := "/usr/location/whatever/man"
|
||||||
|
env := new(MockedEnvironment)
|
||||||
|
env.On("getPathSeperator", nil).Return("/")
|
||||||
|
env.On("homeDir", nil).Return("/usr/home")
|
||||||
|
env.On("getcwd", nil).Return(pwd)
|
||||||
|
path := &path{
|
||||||
|
env: env,
|
||||||
|
props: &properties{
|
||||||
|
values: map[Property]interface{}{
|
||||||
|
FolderSeparatorIcon: " > ",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
got := path.getAgnosterShortPath()
|
||||||
|
assert.Equal(t, "usr > .. > man", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetAgnosterShortPathInsideHome(t *testing.T) {
|
||||||
|
pwd := "/usr/home/whatever/man"
|
||||||
|
env := new(MockedEnvironment)
|
||||||
|
env.On("getPathSeperator", nil).Return("/")
|
||||||
|
env.On("homeDir", nil).Return("/usr/home")
|
||||||
|
env.On("getcwd", nil).Return(pwd)
|
||||||
|
path := &path{
|
||||||
|
env: env,
|
||||||
|
props: &properties{
|
||||||
|
values: map[Property]interface{}{
|
||||||
|
FolderSeparatorIcon: " > ",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
got := path.getAgnosterShortPath()
|
||||||
|
assert.Equal(t, "~ > .. > man", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetAgnosterShortPathInsideHomeOneLevel(t *testing.T) {
|
||||||
|
pwd := "/usr/home/projects"
|
||||||
|
env := new(MockedEnvironment)
|
||||||
|
env.On("getPathSeperator", nil).Return("/")
|
||||||
|
env.On("homeDir", nil).Return("/usr/home")
|
||||||
|
env.On("getcwd", nil).Return(pwd)
|
||||||
|
path := &path{
|
||||||
|
env: env,
|
||||||
|
props: &properties{
|
||||||
|
values: map[Property]interface{}{
|
||||||
|
FolderSeparatorIcon: " > ",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
got := path.getAgnosterShortPath()
|
||||||
|
assert.Equal(t, "~ > projects", got)
|
||||||
|
}
|
||||||
|
|
||||||
func testWritePathInfo(home, pwd, pathSeparator string) string {
|
func testWritePathInfo(home, pwd, pathSeparator string) string {
|
||||||
props := &properties{
|
props := &properties{
|
||||||
values: map[Property]interface{}{
|
values: map[Property]interface{}{
|
||||||
|
|
|
@ -856,6 +856,7 @@
|
||||||
"enum": [
|
"enum": [
|
||||||
"agnoster",
|
"agnoster",
|
||||||
"agnoster_full",
|
"agnoster_full",
|
||||||
|
"agnoster_short",
|
||||||
"short",
|
"short",
|
||||||
"full",
|
"full",
|
||||||
"folder"
|
"folder"
|
||||||
|
|
Loading…
Reference in a new issue