diff --git a/src/segments/path.go b/src/segments/path.go index f60dce27..5c11a38a 100644 --- a/src/segments/path.go +++ b/src/segments/path.go @@ -79,6 +79,8 @@ const ( CycleFolderSeparator properties.Property = "cycle_folder_separator" // format to use on the folder names FolderFormat properties.Property = "folder_format" + // format to use on the first and last folder of the path + EdgeFormat properties.Property = "edge_format" ) func (pt *Path) Template() string { @@ -593,9 +595,9 @@ func (pt *Path) colorizePath(root string, elements []string) string { folderSeparator := pt.getFolderSeparator() colorSeparator := pt.props.GetBool(CycleFolderSeparator, false) folderFormat := pt.props.GetString(FolderFormat, "%s") + edgeFormat := pt.props.GetString(EdgeFormat, folderFormat) colorizeElement := func(element string) string { - element = fmt.Sprintf(folderFormat, element) if skipColorize || len(element) == 0 { return element } @@ -606,6 +608,7 @@ func (pt *Path) colorizePath(root string, elements []string) string { } if len(elements) == 0 { + root := fmt.Sprintf(edgeFormat, root) return colorizeElement(root) } @@ -618,6 +621,7 @@ func (pt *Path) colorizePath(root string, elements []string) string { var builder strings.Builder + root = fmt.Sprintf(edgeFormat, root) builder.WriteString(colorizeElement(root)) if root != pt.env.PathSeparator() && len(root) != 0 { @@ -628,6 +632,13 @@ func (pt *Path) colorizePath(root string, elements []string) string { if len(element) == 0 { continue } + + format := folderFormat + if i == len(elements)-1 { + format = edgeFormat + } + + element = fmt.Sprintf(format, element) builder.WriteString(colorizeElement(element)) if i != len(elements)-1 { builder.WriteString(colorizeSeparator()) diff --git a/themes/schema.json b/themes/schema.json index 2b74d060..a8e0e4fc 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -1801,6 +1801,12 @@ "title": "The folder format", "description": "Golang string format to apply to the folder name", "pattern": ".*%s.*" + }, + "edge_format": { + "type": "string", + "title": "The format to use on the start and end folder", + "description": "Golang string format to apply to the start and end folder", + "pattern": ".*%s.*" } } } diff --git a/website/docs/segments/path.mdx b/website/docs/segments/path.mdx index 18338f0d..84c2ad1a 100644 --- a/website/docs/segments/path.mdx +++ b/website/docs/segments/path.mdx @@ -45,6 +45,7 @@ import Config from "@site/src/components/Config.js"; | `cycle` | `[]string` | a list of color overrides to cycle through to colorize the individual path folders, e.g. `[ "#ffffff,#111111" ]` | | `cycle_folder_separator` | `boolean` | colorize the `folder_separator_icon` as well when using a cycle - defaults to `false` | | `folder_format` | `string` | format to use on individual path folders - defaults to `%s` | +| `edge_format` | `string` | format to use on the first and last folder of the path - defaults to `%s` | ## Mapped Locations