From 2d1c132ecfbf43c9636c401bf4bef6b10a16267d Mon Sep 17 00:00:00 2001 From: Josh Medeski Date: Thu, 16 Mar 2023 11:54:35 -0500 Subject: [PATCH] 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 --- .gitmux.yml | 2 ++ README.md | 2 ++ tmux/formater.go | 6 +++++- tmux/formater_test.go | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/.gitmux.yml b/.gitmux.yml index 5eba027..ef02ebe 100644 --- a/.gitmux.yml +++ b/.gitmux.yml @@ -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 diff --git a/README.md b/README.md index 8258afa..88c257a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/tmux/formater.go b/tmux/formater.go index a20446a..b4219fb 100644 --- a/tmux/formater.go +++ b/tmux/formater.go @@ -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 diff --git a/tmux/formater_test.go b/tmux/formater_test.go index d4b21bc..dc40f5b 100644 --- a/tmux/formater_test.go +++ b/tmux/formater_test.go @@ -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) {