Skip to content

Commit 6a169c6

Browse files
authored
Fix flags_without_count option behavior for empty symbols (#136)
The flags_without_count option was not handling empty symbols correctly. Previously, flags with empty symbols were completely hidden regardless of the option value, but according to the intended behavior, they should show counts when flags_without_count=false (default).
1 parent 70a3133 commit 6a169c6

4 files changed

Lines changed: 318 additions & 47 deletions

File tree

.gitmux.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,6 @@ tmux:
8686
# Add a space between behind & ahead upstream counts.
8787
divergence_space: false
8888
# Show flags symbols without counts.
89+
# When true, shows only symbols (empty symbols show nothing).
90+
# When false (default), shows symbols with counts (empty symbols show counts only).
8991
flags_without_count: false

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,9 @@ This is the list of additional configuration `options`:
296296
| `hide_clean` | Hides the clean flag entirely | `false` |
297297
| `swap_divergence` | Swaps order of behind & ahead upstream counts | `false` |
298298
| `divergence_space` | Add a space between behind & ahead upstream counts | `false` |
299-
| `flags_without_count`| Show flags symbols without counts | `false` |
299+
| `flags_without_count`| Show flags symbols without counts* | `false` |
300+
301+
*When `flags_without_count` is true, shows only symbols (empty symbols show nothing). When false (default), shows symbols with counts (empty symbols show counts only).
300302

301303
## Troubleshooting
302304

tmux/formater.go

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -295,21 +295,31 @@ func (f *Formater) currentRef() string {
295295
return fmt.Sprintf("%s%s%s", f.Styles.Clear, f.Styles.Branch, branch)
296296
}
297297

298-
// formatFlag formats a flag with or without count based on the flags_without_count option
299-
func (f *Formater) formatFlag(style, symbol string, count int) string {
298+
// appendFlag appends a flag to the flags slice based on configuration options
299+
func (f *Formater) appendFlag(flags []string, style, symbol string, count int) []string {
300+
if count == 0 {
301+
return flags
302+
}
303+
300304
if f.Options.FlagsWithoutCount {
301-
return fmt.Sprintf("%s%s", style, symbol)
305+
// When flags_without_count is true, show symbol only (empty string if symbol is empty)
306+
if symbol == "" {
307+
return flags
308+
}
309+
return append(flags, fmt.Sprintf("%s%s", style, symbol))
302310
}
303-
return fmt.Sprintf("%s%s%d", style, symbol, count)
311+
312+
// When flags_without_count is false, show symbol + count, or just count if symbol is empty
313+
return append(flags, fmt.Sprintf("%s%s%d", style, symbol, count))
304314
}
305315

306316
func (f *Formater) flags() string {
307317
var flags []string
308318
if f.st.IsClean {
309-
if f.st.NumStashed != 0 && f.Symbols.Stashed != "" {
310-
flags = append(flags, f.formatFlag(f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed))
311-
}
319+
// For stashed in clean state, handle empty symbols properly
320+
flags = f.appendFlag(flags, f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed)
312321

322+
// Clean flag only shows if symbol is not empty and hide_clean is false
313323
if !f.Options.HideClean && f.Symbols.Clean != "" {
314324
flags = append(flags, fmt.Sprintf("%s%s", f.Styles.Clean, f.Symbols.Clean))
315325
}
@@ -319,25 +329,12 @@ func (f *Formater) flags() string {
319329
}
320330
}
321331

322-
if f.st.NumStaged != 0 && f.Symbols.Staged != "" {
323-
flags = append(flags, f.formatFlag(f.Styles.Staged, f.Symbols.Staged, f.st.NumStaged))
324-
}
325-
326-
if f.st.NumConflicts != 0 && f.Symbols.Conflict != "" {
327-
flags = append(flags, f.formatFlag(f.Styles.Conflict, f.Symbols.Conflict, f.st.NumConflicts))
328-
}
329-
330-
if f.st.NumModified != 0 && f.Symbols.Modified != "" {
331-
flags = append(flags, f.formatFlag(f.Styles.Modified, f.Symbols.Modified, f.st.NumModified))
332-
}
333-
334-
if f.st.NumStashed != 0 && f.Symbols.Stashed != "" {
335-
flags = append(flags, f.formatFlag(f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed))
336-
}
337-
338-
if f.st.NumUntracked != 0 && f.Symbols.Untracked != "" {
339-
flags = append(flags, f.formatFlag(f.Styles.Untracked, f.Symbols.Untracked, f.st.NumUntracked))
340-
}
332+
// For all other flags, handle empty symbols properly
333+
flags = f.appendFlag(flags, f.Styles.Staged, f.Symbols.Staged, f.st.NumStaged)
334+
flags = f.appendFlag(flags, f.Styles.Conflict, f.Symbols.Conflict, f.st.NumConflicts)
335+
flags = f.appendFlag(flags, f.Styles.Modified, f.Symbols.Modified, f.st.NumModified)
336+
flags = f.appendFlag(flags, f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed)
337+
flags = f.appendFlag(flags, f.Styles.Untracked, f.Symbols.Untracked, f.st.NumUntracked)
341338

342339
if len(flags) > 0 {
343340
return f.Styles.Clear + strings.Join(flags, " ")

0 commit comments

Comments
 (0)