feat(path): letter full path

resolves #851
This commit is contained in:
Jan De Dobbeleer 2021-07-13 20:15:53 +02:00 committed by Jan De Dobbeleer
parent 07b9b82f9f
commit 1f4d05415c
4 changed files with 34 additions and 3 deletions

View file

@ -68,6 +68,7 @@ Style sets the way the path is displayed. Based on previous experience and popul
- full
- folder
- mixed
- letter
### 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
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.

View file

@ -35,6 +35,8 @@ const (
Folder string = "folder"
// Mixed like agnoster, but if the path is short it displays it
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 Property = "mixed_threshold"
// MappedLocations allows overriding certain location with an icon
@ -61,6 +63,8 @@ func (pt *path) string() string {
formattedPath = pt.getAgnosterShortPath()
case Mixed:
formattedPath = pt.getMixedPath()
case Letter:
formattedPath = pt.getLetterPath()
case Short:
// "short" is a duplicate of "full", just here for backwards compatibility
fallthrough
@ -128,15 +132,33 @@ func (pt *path) getAgnosterPath() string {
pwd := pt.getPwd()
buffer.WriteString(pt.rootLocation())
pathDepth := pt.pathDepth(pwd)
folderIcon := pt.props.getString(FolderIcon, "..")
separator := pt.props.getString(FolderSeparatorIcon, pt.env.getPathSeperator())
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 {
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()
}
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 {
pwd := pt.getPwd()
if string(pwd[0]) == pt.env.getPathSeperator() {

View file

@ -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: "~ > 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 {
env := new(MockedEnvironment)

View file

@ -1191,7 +1191,8 @@
"short",
"full",
"folder",
"mixed"
"mixed",
"letter"
],
"default": "folder"
},