feat: adds option to hide clean flag (#92)

* 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
This commit is contained in:
Josh Medeski 2023-03-16 11:54:35 -05:00 committed by GitHub
parent 595c9fde2f
commit 2d1c132ecf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 1 deletions

View file

@ -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

View file

@ -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:
@ -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

View file

@ -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.
@ -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

View file

@ -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) {