diff --git a/docs/docs/segment-path.md b/docs/docs/segment-path.md index 749b8c4c..58de87b2 100644 --- a/docs/docs/segment-path.md +++ b/docs/docs/segment-path.md @@ -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. diff --git a/src/segment_path.go b/src/segment_path.go index 8b3f04f6..ea8dd107 100644 --- a/src/segment_path.go +++ b/src/segment_path.go @@ -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() { diff --git a/src/segment_path_test.go b/src/segment_path_test.go index 85d6e371..40e7b927 100644 --- a/src/segment_path_test.go +++ b/src/segment_path_test.go @@ -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) diff --git a/themes/schema.json b/themes/schema.json index 69413e81..3d6b57e4 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -1191,7 +1191,8 @@ "short", "full", "folder", - "mixed" + "mixed", + "letter" ], "default": "folder" },