Skip to content

Commit

Permalink
feat: adds option to hide clean flag (#92)
Browse files Browse the repository at this point in the history
* feat: adds option to hide clean flag

* test: hide clean option

* test: options true and false

* docs: add hide_clean to README

* fix: whitespace in yml example
  • Loading branch information
joshmedeski committed Mar 16, 2023
1 parent 595c9fd commit 2d1c132
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitmux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ tmux:
branch_trim: right
# Character indicating whether and where a branch was truncated.
ellipsis:
# Hides the clean flag
hide_clean: false
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ tmux:
branch_max_len: 0
branch_trim: right
ellipsis:
hide_clean: false
```

First, save the default configuration to a new file:
Expand Down Expand Up @@ -269,6 +270,7 @@ This is the list of additional configuration `options`:
| `branch_max_len` | Maximum displayed length for local and remote branch names | `0` (no limit) |
| `branch_trim` | Trim left or right end of the branch (`right` or `left`) | `right` (trailing) |
| `ellipsis` | Character to show branch name has been truncated | `` |
| `hide_clean` | Hides the clean flag entirely | `false` |


## Troubleshooting
Expand Down
6 changes: 5 additions & 1 deletion tmux/formater.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type options struct {
BranchMaxLen int `yaml:"branch_max_len"`
BranchTrim direction `yaml:"branch_trim"`
Ellipsis string `yaml:"ellipsis"`
HideClean bool `yaml:"hide_clean"`
}

// A Formater formats git status to a tmux style string.
Expand Down Expand Up @@ -256,7 +257,10 @@ func (f *Formater) flags() {
fmt.Sprintf("%s%s%d", f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed))
}

flags = append(flags, fmt.Sprintf("%s%s", f.Styles.Clean, f.Symbols.Clean))
if f.Options.HideClean != true {
flags = append(flags, fmt.Sprintf("%s%s", f.Styles.Clean, f.Symbols.Clean))
}

f.clear()
f.b.WriteString(strings.Join(flags, " "))
return
Expand Down
36 changes: 36 additions & 0 deletions tmux/formater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,42 @@ func TestFormat(t *testing.T) {
want: "StyleClear" + "StyleBranch" + "SymbolBranch" +
"StyleClear" + "StyleBranch" + "branchName",
},
{
name: "hide clean option true",
styles: styles{
Clear: "StyleClear",
Clean: "StyleClean",
},
symbols: symbols{
Clean: "SymbolClean",
},
layout: []string{"flags"},
st: &gitstatus.Status{
IsClean: true,
},
options: options{
HideClean: true,
},
want: "StyleClear",
},
{
name: "hide clean option false",
styles: styles{
Clear: "StyleClear",
Clean: "StyleClean",
},
symbols: symbols{
Clean: "SymbolClean",
},
layout: []string{"flags"},
st: &gitstatus.Status{
IsClean: true,
},
options: options{
HideClean: false,
},
want: "StyleClear" + "StyleCleanSymbolClean",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 2d1c132

Please sign in to comment.