mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-15 13:17:53 -08:00
feat: added Mixed path option - displays the path if it's short enough
This commit is contained in:
parent
4750d19d86
commit
c71c5e86cb
|
@ -38,6 +38,8 @@ is set to `true`)
|
||||||
- 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`
|
||||||
- enable_hyperlink: `boolean` - displays an hyperlink for the path - defaults to `false`
|
- enable_hyperlink: `boolean` - displays an hyperlink for the path - defaults to `false`
|
||||||
|
- mixed_threshold: `number` - the maximum length of a path segment that will be displayed when using `Mixed` -
|
||||||
|
defaults to `4`
|
||||||
|
|
||||||
## Style
|
## Style
|
||||||
|
|
||||||
|
@ -48,6 +50,7 @@ Style sets the way the path is displayed. Based on previous experience and popul
|
||||||
- agnoster_short
|
- agnoster_short
|
||||||
- full
|
- full
|
||||||
- folder
|
- folder
|
||||||
|
- mixed
|
||||||
|
|
||||||
### Agnoster
|
### Agnoster
|
||||||
|
|
||||||
|
@ -70,3 +73,8 @@ Display `$PWD` as a string.
|
||||||
### Folder
|
### Folder
|
||||||
|
|
||||||
Display the name of the current folder.
|
Display the name of the current folder.
|
||||||
|
|
||||||
|
### Mixed
|
||||||
|
|
||||||
|
Works like `Agnoster Full`, but for any middle folder short enough it will display its name instead. The maximum length
|
||||||
|
for the folders to display is governed by the `mixed_threshold` property.
|
||||||
|
|
|
@ -33,6 +33,10 @@ const (
|
||||||
Full string = "full"
|
Full string = "full"
|
||||||
// Folder displays the current folder
|
// Folder displays the current folder
|
||||||
Folder string = "folder"
|
Folder string = "folder"
|
||||||
|
// Mixed like agnoster, but if the path is short it displays it
|
||||||
|
Mixed string = "mixed"
|
||||||
|
// MixedThreshold the threshold of the length of the path Mixed will display
|
||||||
|
MixedThreshold Property = "mixed_threshold"
|
||||||
// MappedLocations allows overriding certain location with an icon
|
// MappedLocations allows overriding certain location with an icon
|
||||||
MappedLocations Property = "mapped_locations"
|
MappedLocations Property = "mapped_locations"
|
||||||
// MappedLocationsEnabled enables overriding certain locations with an icon
|
// MappedLocationsEnabled enables overriding certain locations with an icon
|
||||||
|
@ -53,6 +57,8 @@ func (pt *path) string() string {
|
||||||
formattedPath = pt.getAgnosterFullPath()
|
formattedPath = pt.getAgnosterFullPath()
|
||||||
case AgnosterShort:
|
case AgnosterShort:
|
||||||
formattedPath = pt.getAgnosterShortPath()
|
formattedPath = pt.getAgnosterShortPath()
|
||||||
|
case Mixed:
|
||||||
|
formattedPath = pt.getMixedPath()
|
||||||
case Short:
|
case Short:
|
||||||
// "short" is a duplicate of "full", just here for backwards compatibility
|
// "short" is a duplicate of "full", just here for backwards compatibility
|
||||||
fallthrough
|
fallthrough
|
||||||
|
@ -80,6 +86,30 @@ func (pt *path) init(props *properties, env environmentInfo) {
|
||||||
pt.env = env
|
pt.env = env
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pt *path) getMixedPath() string {
|
||||||
|
var buffer strings.Builder
|
||||||
|
pwd := pt.getPwd()
|
||||||
|
splitted := strings.Split(pwd, pt.env.getPathSeperator())
|
||||||
|
threshold := int(pt.props.getFloat64(MixedThreshold, 4))
|
||||||
|
for i, part := range splitted {
|
||||||
|
if part == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
folder := part
|
||||||
|
if len(part) > threshold && i != 0 && i != len(splitted)-1 {
|
||||||
|
folder = pt.props.getString(FolderIcon, "..")
|
||||||
|
}
|
||||||
|
separator := pt.props.getString(FolderSeparatorIcon, pt.env.getPathSeperator())
|
||||||
|
if i == 0 {
|
||||||
|
separator = ""
|
||||||
|
}
|
||||||
|
buffer.WriteString(fmt.Sprintf("%s%s", separator, folder))
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer.String()
|
||||||
|
}
|
||||||
|
|
||||||
func (pt *path) getAgnosterPath() string {
|
func (pt *path) getAgnosterPath() string {
|
||||||
var buffer strings.Builder
|
var buffer strings.Builder
|
||||||
pwd := pt.getPwd()
|
pwd := pt.getPwd()
|
||||||
|
|
|
@ -280,6 +280,9 @@ func TestAgnosterPathStyles(t *testing.T) {
|
||||||
|
|
||||||
{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: " | "},
|
||||||
|
|
||||||
|
{Style: Mixed, Expected: "~ > .. > man", HomePath: "/usr/home", Pwd: "/usr/home/whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
|
||||||
|
{Style: Mixed, Expected: "~ > ab > .. > man", HomePath: "/usr/home", Pwd: "/usr/home/ab/whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
|
||||||
}
|
}
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
|
|
Loading…
Reference in a new issue