mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
parent
6e874f97d8
commit
6af47a61d5
|
@ -58,6 +58,9 @@ const (
|
||||||
Unique string = "unique"
|
Unique string = "unique"
|
||||||
// AgnosterLeft like agnoster, but keeps the left side of the path
|
// AgnosterLeft like agnoster, but keeps the left side of the path
|
||||||
AgnosterLeft string = "agnoster_left"
|
AgnosterLeft string = "agnoster_left"
|
||||||
|
// Powerlevel tries to mimic the powerlevel10k path,
|
||||||
|
// used in combination with max_width.
|
||||||
|
Powerlevel string = "powerlevel"
|
||||||
// MixedThreshold the threshold of the length of the path Mixed will display
|
// MixedThreshold the threshold of the length of the path Mixed will display
|
||||||
MixedThreshold properties.Property = "mixed_threshold"
|
MixedThreshold properties.Property = "mixed_threshold"
|
||||||
// MappedLocations allows overriding certain location with an icon
|
// MappedLocations allows overriding certain location with an icon
|
||||||
|
@ -66,6 +69,8 @@ const (
|
||||||
MappedLocationsEnabled properties.Property = "mapped_locations_enabled"
|
MappedLocationsEnabled properties.Property = "mapped_locations_enabled"
|
||||||
// MaxDepth Maximum path depth to display whithout shortening
|
// MaxDepth Maximum path depth to display whithout shortening
|
||||||
MaxDepth properties.Property = "max_depth"
|
MaxDepth properties.Property = "max_depth"
|
||||||
|
// MaxWidth Maximum path width to display for powerlevel style
|
||||||
|
MaxWidth properties.Property = "max_width"
|
||||||
// Hides the root location if it doesn't fit in max_depth. Used in Agnoster Short
|
// Hides the root location if it doesn't fit in max_depth. Used in Agnoster Short
|
||||||
HideRootLocation properties.Property = "hide_root_location"
|
HideRootLocation properties.Property = "hide_root_location"
|
||||||
)
|
)
|
||||||
|
@ -152,7 +157,7 @@ func (pt *Path) setStyle() {
|
||||||
case Letter:
|
case Letter:
|
||||||
pt.Path = pt.getLetterPath()
|
pt.Path = pt.getLetterPath()
|
||||||
case Unique:
|
case Unique:
|
||||||
pt.Path = pt.getUniqueLettersPath()
|
pt.Path = pt.getUniqueLettersPath(0)
|
||||||
case AgnosterLeft:
|
case AgnosterLeft:
|
||||||
pt.Path = pt.getAgnosterLeftPath()
|
pt.Path = pt.getAgnosterLeftPath()
|
||||||
case Short:
|
case Short:
|
||||||
|
@ -162,6 +167,9 @@ func (pt *Path) setStyle() {
|
||||||
pt.Path = pt.getFullPath()
|
pt.Path = pt.getFullPath()
|
||||||
case Folder:
|
case Folder:
|
||||||
pt.Path = pt.getFolderPath()
|
pt.Path = pt.getFolderPath()
|
||||||
|
case Powerlevel:
|
||||||
|
maxWidth := int(pt.props.GetFloat64(MaxWidth, 0))
|
||||||
|
pt.Path = pt.getUniqueLettersPath(maxWidth)
|
||||||
default:
|
default:
|
||||||
pt.Path = fmt.Sprintf("Path style: %s is not available", style)
|
pt.Path = fmt.Sprintf("Path style: %s is not available", style)
|
||||||
}
|
}
|
||||||
|
@ -294,7 +302,7 @@ func (pt *Path) getLetterPath() string {
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pt *Path) getUniqueLettersPath() string {
|
func (pt *Path) getUniqueLettersPath(maxWidth int) string {
|
||||||
var buffer strings.Builder
|
var buffer strings.Builder
|
||||||
separator := pt.getFolderSeparator()
|
separator := pt.getFolderSeparator()
|
||||||
elements := strings.Split(pt.relative, pt.env.PathSeparator())
|
elements := strings.Split(pt.relative, pt.env.PathSeparator())
|
||||||
|
@ -317,6 +325,16 @@ func (pt *Path) getUniqueLettersPath() string {
|
||||||
buffer.WriteString(separator)
|
buffer.WriteString(separator)
|
||||||
}
|
}
|
||||||
buffer.WriteString(letter)
|
buffer.WriteString(letter)
|
||||||
|
// only return early on maxWidth > 0
|
||||||
|
// this enables the powerlevel10k behavior
|
||||||
|
if maxWidth > 0 {
|
||||||
|
trailing := strings.Join(elements[i+1:], separator)
|
||||||
|
leftover := maxWidth - buffer.Len() - len(trailing) - len(separator)
|
||||||
|
if leftover >= 0 {
|
||||||
|
buffer.WriteString(fmt.Sprintf("%s%s", separator, trailing))
|
||||||
|
return buffer.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buffer.WriteString(fmt.Sprintf("%s%s", separator, elements[n-1]))
|
buffer.WriteString(fmt.Sprintf("%s%s", separator, elements[n-1]))
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
|
|
|
@ -162,6 +162,7 @@ func TestAgnosterPathStyles(t *testing.T) {
|
||||||
FolderSeparatorIcon string
|
FolderSeparatorIcon string
|
||||||
GOOS string
|
GOOS string
|
||||||
MaxDepth int
|
MaxDepth int
|
||||||
|
MaxWidth int
|
||||||
HideRootLocation bool
|
HideRootLocation bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -198,6 +199,25 @@ func TestAgnosterPathStyles(t *testing.T) {
|
||||||
FolderSeparatorIcon: " > ",
|
FolderSeparatorIcon: " > ",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
Style: Powerlevel,
|
||||||
|
Expected: "t > w > o > a > v > l > p > wh > we > i > wa > th > the > d > f > u > it > c > to > a > co > stream",
|
||||||
|
HomePath: homeDir,
|
||||||
|
Pwd: "there/was/once/a/very/long/path/which/wended/its/way/through/the/dark/forest/until/it/came/to/a/cold/stream",
|
||||||
|
PathSeparator: "/",
|
||||||
|
FolderSeparatorIcon: " > ",
|
||||||
|
MaxWidth: 20,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Style: Powerlevel,
|
||||||
|
Expected: "t > w > o > a > v > l > p > which > wended > its > way > through > the",
|
||||||
|
HomePath: homeDir,
|
||||||
|
Pwd: "there/was/once/a/very/long/path/which/wended/its/way/through/the",
|
||||||
|
PathSeparator: "/",
|
||||||
|
FolderSeparatorIcon: " > ",
|
||||||
|
MaxWidth: 70,
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
Style: Letter,
|
Style: Letter,
|
||||||
Expected: "~",
|
Expected: "~",
|
||||||
|
@ -696,6 +716,7 @@ func TestAgnosterPathStyles(t *testing.T) {
|
||||||
FolderSeparatorIcon: tc.FolderSeparatorIcon,
|
FolderSeparatorIcon: tc.FolderSeparatorIcon,
|
||||||
properties.Style: tc.Style,
|
properties.Style: tc.Style,
|
||||||
MaxDepth: tc.MaxDepth,
|
MaxDepth: tc.MaxDepth,
|
||||||
|
MaxWidth: tc.MaxWidth,
|
||||||
HideRootLocation: tc.HideRootLocation,
|
HideRootLocation: tc.HideRootLocation,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1740,7 +1740,8 @@
|
||||||
"folder",
|
"folder",
|
||||||
"mixed",
|
"mixed",
|
||||||
"letter",
|
"letter",
|
||||||
"unique"
|
"unique",
|
||||||
|
"powerlevel"
|
||||||
],
|
],
|
||||||
"default": "folder"
|
"default": "folder"
|
||||||
},
|
},
|
||||||
|
|
|
@ -38,6 +38,7 @@ Display the current path.
|
||||||
| `style` | `enum` | how to display the current path |
|
| `style` | `enum` | how to display the current path |
|
||||||
| `mixed_threshold` | `number` | the maximum length of a path segment that will be displayed when using `Mixed` - defaults to `4` |
|
| `mixed_threshold` | `number` | the maximum length of a path segment that will be displayed when using `Mixed` - defaults to `4` |
|
||||||
| `max_depth` | `number` | maximum path depth to display before shortening when using `agnoster_short`, defaults to `1` |
|
| `max_depth` | `number` | maximum path depth to display before shortening when using `agnoster_short`, defaults to `1` |
|
||||||
|
| `max_width` | `number` | maximum path length to display when using `powerlevel`, defaults to `0` |
|
||||||
| `hide_root_location` | `boolean` | hides the root location if it doesn't fit in the last `max_depth` folders, when using `agnoster_short` - defaults to `false` |
|
| `hide_root_location` | `boolean` | hides the root location if it doesn't fit in the last `max_depth` folders, when using `agnoster_short` - defaults to `false` |
|
||||||
|
|
||||||
## Mapped Locations
|
## Mapped Locations
|
||||||
|
@ -74,7 +75,7 @@ For example, to swap out `C:\Users\Leet\GitHub` with a GitHub icon, you can do t
|
||||||
|
|
||||||
## Style
|
## Style
|
||||||
|
|
||||||
Style sets the way the path is displayed. Based on previous experience and popular themes, there are 5 flavors.
|
Style sets the way the path is displayed. Based on previous experience and popular themes, there are 10 flavors.
|
||||||
|
|
||||||
- `agnoster`
|
- `agnoster`
|
||||||
- `agnoster_full`
|
- `agnoster_full`
|
||||||
|
@ -85,6 +86,7 @@ Style sets the way the path is displayed. Based on previous experience and popul
|
||||||
- `mixed`
|
- `mixed`
|
||||||
- `letter`
|
- `letter`
|
||||||
- `unique`
|
- `unique`
|
||||||
|
- `powerlevel`
|
||||||
|
|
||||||
### Agnoster
|
### Agnoster
|
||||||
|
|
||||||
|
@ -138,6 +140,10 @@ The uniqueness refers to the displayed path, so `C:\dev\dev\dev\development` wil
|
||||||
folders at the same level, so if `C:\projectA\dev` and `C:\projectB\dev` exist, then both will be displayed as
|
folders at the same level, so if `C:\projectA\dev` and `C:\projectB\dev` exist, then both will be displayed as
|
||||||
`C\p\dev`.
|
`C\p\dev`.
|
||||||
|
|
||||||
|
### Powerlevel
|
||||||
|
|
||||||
|
Works like `Unique`, but will stop shortening when `max_width` is reached.
|
||||||
|
|
||||||
## Template ([info][templates])
|
## Template ([info][templates])
|
||||||
|
|
||||||
:::note default template
|
:::note default template
|
||||||
|
|
Loading…
Reference in a new issue