mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-26 19:39:39 -08:00
feat(path): add option to colorize first and last folder
This commit is contained in:
parent
736e092024
commit
4c0c596c2c
|
@ -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())
|
||||
|
|
|
@ -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.*"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue