mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
feat(path): add 'max_depth' option for 'agnoster_short'
This commit is contained in:
parent
2470abcc86
commit
2b53796c1a
|
@ -38,6 +38,7 @@ Display the current path.
|
||||||
- mixed_threshold: `number` - the maximum length of a path segment that will be displayed when using `Mixed` -
|
- mixed_threshold: `number` - the maximum length of a path segment that will be displayed when using `Mixed` -
|
||||||
defaults to `4`
|
defaults to `4`
|
||||||
- stack_count_enabled: `boolean` - displays the stack count when using pushd/popd - defaults to `false`
|
- stack_count_enabled: `boolean` - displays the stack count when using pushd/popd - defaults to `false`
|
||||||
|
- max_depth: `number` - maximum path depth to display before shortening when using `Agnoster Short` - defaults to `1`
|
||||||
|
|
||||||
## Mapped Locations
|
## Mapped Locations
|
||||||
|
|
||||||
|
@ -82,7 +83,8 @@ Renders each folder name separated by the `folder_separator_icon`.
|
||||||
|
|
||||||
### Agnoster Short
|
### 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`.
|
When more than `max_depth` levels deep, it renders one `folder_icon` followed by the names of the last `max_depth` folders,
|
||||||
|
separated by the `folder_separator_icon`.
|
||||||
|
|
||||||
### Full
|
### Full
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,8 @@ const (
|
||||||
MappedLocationsEnabled Property = "mapped_locations_enabled"
|
MappedLocationsEnabled Property = "mapped_locations_enabled"
|
||||||
// StackCountEnabled enables the stack count display
|
// StackCountEnabled enables the stack count display
|
||||||
StackCountEnabled Property = "stack_count_enabled"
|
StackCountEnabled Property = "stack_count_enabled"
|
||||||
|
// Maximum path depth to display whithout shortening
|
||||||
|
MaxDepth Property = "max_depth"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (pt *path) enabled() bool {
|
func (pt *path) enabled() bool {
|
||||||
|
@ -174,20 +176,28 @@ func (pt *path) getAgnosterFullPath() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pt *path) getAgnosterShortPath() string {
|
func (pt *path) getAgnosterShortPath() string {
|
||||||
|
pwd := pt.getPwd()
|
||||||
|
pathDepth := pt.pathDepth(pwd)
|
||||||
|
maxDepth := pt.props.getInt(MaxDepth, 1)
|
||||||
|
if maxDepth < 1 {
|
||||||
|
maxDepth = 1
|
||||||
|
}
|
||||||
|
if pathDepth <= maxDepth {
|
||||||
|
return pt.getAgnosterFullPath()
|
||||||
|
}
|
||||||
pathSeparator := pt.env.getPathSeperator()
|
pathSeparator := pt.env.getPathSeperator()
|
||||||
folderSeparator := pt.props.getString(FolderSeparatorIcon, pathSeparator)
|
folderSeparator := pt.props.getString(FolderSeparatorIcon, pathSeparator)
|
||||||
folderIcon := pt.props.getString(FolderIcon, "..")
|
folderIcon := pt.props.getString(FolderIcon, "..")
|
||||||
root := pt.rootLocation()
|
root := pt.rootLocation()
|
||||||
pwd := pt.getPwd()
|
splitted := strings.Split(pwd, pathSeparator)
|
||||||
base := base(pwd, pt.env)
|
fullPathDepth := len(splitted)
|
||||||
pathDepth := pt.pathDepth(pwd)
|
splitPos := fullPathDepth - maxDepth
|
||||||
if pathDepth <= 0 {
|
var buffer strings.Builder
|
||||||
return root
|
buffer.WriteString(fmt.Sprintf("%s%s%s", root, folderSeparator, folderIcon))
|
||||||
|
for i := splitPos; i < fullPathDepth; i++ {
|
||||||
|
buffer.WriteString(fmt.Sprintf("%s%s", folderSeparator, splitted[i]))
|
||||||
}
|
}
|
||||||
if pathDepth == 1 {
|
return buffer.String()
|
||||||
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) getFullPath() string {
|
func (pt *path) getFullPath() string {
|
||||||
|
|
|
@ -282,6 +282,7 @@ func TestAgnosterPathStyles(t *testing.T) {
|
||||||
FolderSeparatorIcon string
|
FolderSeparatorIcon string
|
||||||
Style string
|
Style string
|
||||||
GOOS string
|
GOOS string
|
||||||
|
MaxDepth int
|
||||||
}{
|
}{
|
||||||
{Style: AgnosterFull, Expected: "usr > location > whatever", HomePath: "/usr/home", Pwd: "/usr/location/whatever", PathSeperator: "/", FolderSeparatorIcon: " > "},
|
{Style: AgnosterFull, Expected: "usr > location > whatever", HomePath: "/usr/home", Pwd: "/usr/location/whatever", PathSeperator: "/", FolderSeparatorIcon: " > "},
|
||||||
{Style: AgnosterShort, Expected: "usr > .. > man", HomePath: "/usr/home", Pwd: "/usr/location/whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
|
{Style: AgnosterShort, Expected: "usr > .. > man", HomePath: "/usr/home", Pwd: "/usr/location/whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
|
||||||
|
@ -291,6 +292,48 @@ func TestAgnosterPathStyles(t *testing.T) {
|
||||||
{Style: AgnosterShort, Expected: "", HomePath: homeBillWindows, Pwd: "/", PathSeperator: "/", FolderSeparatorIcon: " > "},
|
{Style: AgnosterShort, Expected: "", HomePath: homeBillWindows, Pwd: "/", PathSeperator: "/", FolderSeparatorIcon: " > "},
|
||||||
{Style: AgnosterShort, Expected: "foo", HomePath: homeBillWindows, Pwd: "/foo", PathSeperator: "/", FolderSeparatorIcon: " > "},
|
{Style: AgnosterShort, Expected: "foo", HomePath: homeBillWindows, Pwd: "/foo", PathSeperator: "/", FolderSeparatorIcon: " > "},
|
||||||
|
|
||||||
|
{Style: AgnosterShort, Expected: "usr > .. > bar > man", HomePath: "/usr/home", Pwd: "/usr/foo/bar/man", PathSeperator: "/", FolderSeparatorIcon: " > ", MaxDepth: 2},
|
||||||
|
{Style: AgnosterShort, Expected: "usr > foo > bar > man", HomePath: "/usr/home", Pwd: "/usr/foo/bar/man", PathSeperator: "/", FolderSeparatorIcon: " > ", MaxDepth: 3},
|
||||||
|
{Style: AgnosterShort, Expected: "~ > .. > bar > man", HomePath: "/usr/home", Pwd: "/usr/home/foo/bar/man", PathSeperator: "/", FolderSeparatorIcon: " > ", MaxDepth: 2},
|
||||||
|
{Style: AgnosterShort, Expected: "~ > foo > bar > man", HomePath: "/usr/home", Pwd: "/usr/home/foo/bar/man", PathSeperator: "/", FolderSeparatorIcon: " > ", MaxDepth: 3},
|
||||||
|
|
||||||
|
{
|
||||||
|
Style: AgnosterShort,
|
||||||
|
Expected: "C: > .. > bar > man",
|
||||||
|
HomePath: homeBillWindows,
|
||||||
|
Pwd: "C:\\usr\\foo\\bar\\man",
|
||||||
|
PathSeperator: "\\",
|
||||||
|
FolderSeparatorIcon: " > ",
|
||||||
|
MaxDepth: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Style: AgnosterShort,
|
||||||
|
Expected: "C: > .. > foo > bar > man",
|
||||||
|
HomePath: homeBillWindows,
|
||||||
|
Pwd: "C:\\usr\\foo\\bar\\man",
|
||||||
|
PathSeperator: "\\",
|
||||||
|
FolderSeparatorIcon: " > ",
|
||||||
|
MaxDepth: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Style: AgnosterShort,
|
||||||
|
Expected: "~ > .. > bar > man",
|
||||||
|
HomePath: homeBillWindows,
|
||||||
|
Pwd: "C:\\Users\\Bill\\foo\\bar\\man",
|
||||||
|
PathSeperator: "\\",
|
||||||
|
FolderSeparatorIcon: " > ",
|
||||||
|
MaxDepth: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Style: AgnosterShort,
|
||||||
|
Expected: "~ > foo > bar > man",
|
||||||
|
HomePath: homeBillWindows,
|
||||||
|
Pwd: "C:\\Users\\Bill\\foo\\bar\\man",
|
||||||
|
PathSeperator: "\\",
|
||||||
|
FolderSeparatorIcon: " > ",
|
||||||
|
MaxDepth: 3,
|
||||||
|
},
|
||||||
|
|
||||||
{Style: AgnosterFull, Expected: "PSDRIVE: | src", HomePath: homeBillWindows, Pwd: "/foo", Pswd: "PSDRIVE:/src", PathSeperator: "/", FolderSeparatorIcon: " | "},
|
{Style: AgnosterFull, Expected: "PSDRIVE: | src", HomePath: homeBillWindows, Pwd: "/foo", Pswd: "PSDRIVE:/src", PathSeperator: "/", FolderSeparatorIcon: " | "},
|
||||||
{Style: AgnosterShort, Expected: "PSDRIVE: | .. | init", HomePath: homeBillWindows, Pwd: "/foo", Pswd: "PSDRIVE:/src/init", PathSeperator: "/", FolderSeparatorIcon: " | "},
|
{Style: AgnosterShort, Expected: "PSDRIVE: | .. | init", HomePath: homeBillWindows, Pwd: "/foo", Pswd: "PSDRIVE:/src/init", PathSeperator: "/", FolderSeparatorIcon: " | "},
|
||||||
|
|
||||||
|
@ -318,6 +361,7 @@ func TestAgnosterPathStyles(t *testing.T) {
|
||||||
values: map[Property]interface{}{
|
values: map[Property]interface{}{
|
||||||
FolderSeparatorIcon: tc.FolderSeparatorIcon,
|
FolderSeparatorIcon: tc.FolderSeparatorIcon,
|
||||||
Style: tc.Style,
|
Style: tc.Style,
|
||||||
|
MaxDepth: tc.MaxDepth,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1232,6 +1232,12 @@
|
||||||
"title": "Mapped Locations",
|
"title": "Mapped Locations",
|
||||||
"description": "Custom glyph/text for specific paths",
|
"description": "Custom glyph/text for specific paths",
|
||||||
"default": {}
|
"default": {}
|
||||||
|
},
|
||||||
|
"max_depth": {
|
||||||
|
"type": "integer",
|
||||||
|
"title": "Maximum Depth",
|
||||||
|
"description": "Maximum path depth to display whithout shortening",
|
||||||
|
"default": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"mapped_locations_enabled": {
|
"mapped_locations_enabled": {
|
||||||
|
|
Loading…
Reference in a new issue