Skip to content

Commit

Permalink
feat(path): allow left and right formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Apr 3, 2024
1 parent 4e22e49 commit c4e11fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/segments/path.go
Expand Up @@ -82,6 +82,10 @@ const (
FolderFormat properties.Property = "folder_format"
// format to use on the first and last folder of the path
EdgeFormat properties.Property = "edge_format"
// format to use on first folder of the path
LeftFormat properties.Property = "left_format"
// format to use on the last folder of the path
RightFormat properties.Property = "right_format"
// GitDirFormat format to use on the git directory
GitDirFormat properties.Property = "gitdir_format"
)
Expand Down Expand Up @@ -622,7 +626,10 @@ 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)
leftFormat := pt.props.GetString(LeftFormat, edgeFormat)
rightFormat := pt.props.GetString(RightFormat, edgeFormat)

colorizeElement := func(element string) string {
if skipColorize || len(element) == 0 {
Expand All @@ -635,7 +642,7 @@ func (pt *Path) colorizePath(root string, elements []string) string {
}

if len(elements) == 0 {
root := fmt.Sprintf(edgeFormat, root)
root := fmt.Sprintf(leftFormat, root)
return colorizeElement(root)
}

Expand All @@ -648,7 +655,7 @@ func (pt *Path) colorizePath(root string, elements []string) string {

var builder strings.Builder

root = fmt.Sprintf(edgeFormat, root)
root = fmt.Sprintf(leftFormat, root)
builder.WriteString(colorizeElement(root))

if root != pt.env.PathSeparator() && len(root) != 0 {
Expand All @@ -662,7 +669,7 @@ func (pt *Path) colorizePath(root string, elements []string) string {

format := folderFormat
if i == len(elements)-1 {
format = edgeFormat
format = rightFormat
}

element = fmt.Sprintf(format, element)
Expand Down
2 changes: 2 additions & 0 deletions website/docs/segments/path.mdx
Expand Up @@ -46,6 +46,8 @@ import Config from "@site/src/components/Config.js";
| `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` |
| `left_format` | `string` | format to use on the firstfolder of the path - defaults to `edge_format` |
| `right_format` | `string` | format to use on the last folder of the path - defaults to `edge_format` |
| `gitdir_format` | `string` | format to use for a git root directory - defaults to `` |

## Mapped Locations
Expand Down

0 comments on commit c4e11fe

Please sign in to comment.