mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
parent
07b9b82f9f
commit
1f4d05415c
|
@ -68,6 +68,7 @@ Style sets the way the path is displayed. Based on previous experience and popul
|
||||||
- full
|
- full
|
||||||
- folder
|
- folder
|
||||||
- mixed
|
- mixed
|
||||||
|
- letter
|
||||||
|
|
||||||
### Agnoster
|
### Agnoster
|
||||||
|
|
||||||
|
@ -95,3 +96,7 @@ Display the name of the current folder.
|
||||||
|
|
||||||
Works like `Agnoster Full`, but for any middle folder short enough it will display its name instead. The maximum length
|
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.
|
for the folders to display is governed by the `mixed_threshold` property.
|
||||||
|
|
||||||
|
### Letter
|
||||||
|
|
||||||
|
Works like `Full`, but will write every subfolder name using the first letter only.
|
||||||
|
|
|
@ -35,6 +35,8 @@ const (
|
||||||
Folder string = "folder"
|
Folder string = "folder"
|
||||||
// Mixed like agnoster, but if the path is short it displays it
|
// Mixed like agnoster, but if the path is short it displays it
|
||||||
Mixed string = "mixed"
|
Mixed string = "mixed"
|
||||||
|
// Letter like agnoster, but with the first letter of each folder name
|
||||||
|
Letter string = "letter"
|
||||||
// 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 Property = "mixed_threshold"
|
MixedThreshold Property = "mixed_threshold"
|
||||||
// MappedLocations allows overriding certain location with an icon
|
// MappedLocations allows overriding certain location with an icon
|
||||||
|
@ -61,6 +63,8 @@ func (pt *path) string() string {
|
||||||
formattedPath = pt.getAgnosterShortPath()
|
formattedPath = pt.getAgnosterShortPath()
|
||||||
case Mixed:
|
case Mixed:
|
||||||
formattedPath = pt.getMixedPath()
|
formattedPath = pt.getMixedPath()
|
||||||
|
case Letter:
|
||||||
|
formattedPath = pt.getLetterPath()
|
||||||
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
|
||||||
|
@ -128,15 +132,33 @@ func (pt *path) getAgnosterPath() string {
|
||||||
pwd := pt.getPwd()
|
pwd := pt.getPwd()
|
||||||
buffer.WriteString(pt.rootLocation())
|
buffer.WriteString(pt.rootLocation())
|
||||||
pathDepth := pt.pathDepth(pwd)
|
pathDepth := pt.pathDepth(pwd)
|
||||||
|
folderIcon := pt.props.getString(FolderIcon, "..")
|
||||||
|
separator := pt.props.getString(FolderSeparatorIcon, pt.env.getPathSeperator())
|
||||||
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", separator, folderIcon))
|
||||||
}
|
}
|
||||||
if pathDepth > 0 {
|
if pathDepth > 0 {
|
||||||
buffer.WriteString(fmt.Sprintf("%s%s", pt.props.getString(FolderSeparatorIcon, pt.env.getPathSeperator()), base(pwd, pt.env)))
|
buffer.WriteString(fmt.Sprintf("%s%s", separator, base(pwd, pt.env)))
|
||||||
}
|
}
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pt *path) getLetterPath() string {
|
||||||
|
var buffer strings.Builder
|
||||||
|
pwd := pt.getPwd()
|
||||||
|
splitted := strings.Split(pwd, pt.env.getPathSeperator())
|
||||||
|
separator := pt.props.getString(FolderSeparatorIcon, pt.env.getPathSeperator())
|
||||||
|
for i := 0; i < len(splitted)-1; i++ {
|
||||||
|
if len(splitted[i]) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
letter := []rune(splitted[i])[0]
|
||||||
|
buffer.WriteString(fmt.Sprintf("%c%s", letter, separator))
|
||||||
|
}
|
||||||
|
buffer.WriteString(splitted[len(splitted)-1])
|
||||||
|
return buffer.String()
|
||||||
|
}
|
||||||
|
|
||||||
func (pt *path) getAgnosterFullPath() string {
|
func (pt *path) getAgnosterFullPath() string {
|
||||||
pwd := pt.getPwd()
|
pwd := pt.getPwd()
|
||||||
if string(pwd[0]) == pt.env.getPathSeperator() {
|
if string(pwd[0]) == pt.env.getPathSeperator() {
|
||||||
|
|
|
@ -296,6 +296,9 @@ func TestAgnosterPathStyles(t *testing.T) {
|
||||||
|
|
||||||
{Style: Mixed, Expected: "~ > .. > man", HomePath: "/usr/home", Pwd: "/usr/home/whatever/man", 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: " > "},
|
{Style: Mixed, Expected: "~ > ab > .. > man", HomePath: "/usr/home", Pwd: "/usr/home/ab/whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
|
||||||
|
|
||||||
|
{Style: Letter, Expected: "~ > a > w > man", HomePath: "/usr/home", Pwd: "/usr/home/ab/whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
|
||||||
|
{Style: Letter, Expected: "u > b > a > w > man", HomePath: "/usr/home", Pwd: "/usr/burp/ab/whatever/man", PathSeperator: "/", FolderSeparatorIcon: " > "},
|
||||||
}
|
}
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
|
|
|
@ -1191,7 +1191,8 @@
|
||||||
"short",
|
"short",
|
||||||
"full",
|
"full",
|
||||||
"folder",
|
"folder",
|
||||||
"mixed"
|
"mixed",
|
||||||
|
"letter"
|
||||||
],
|
],
|
||||||
"default": "folder"
|
"default": "folder"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue