Skip to content

Fix flags_without_count option behavior for empty symbols #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitmux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,6 @@ tmux:
# Add a space between behind & ahead upstream counts.
divergence_space: false
# Show flags symbols without counts.
# When true, shows only symbols (empty symbols show nothing).
# When false (default), shows symbols with counts (empty symbols show counts only).
flags_without_count: false
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ This is the list of additional configuration `options`:
| `hide_clean` | Hides the clean flag entirely | `false` |
| `swap_divergence` | Swaps order of behind & ahead upstream counts | `false` |
| `divergence_space` | Add a space between behind & ahead upstream counts | `false` |
| `flags_without_count`| Show flags symbols without counts | `false` |
| `flags_without_count`| Show flags symbols without counts* | `false` |

*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).

## Troubleshooting

Expand Down
49 changes: 23 additions & 26 deletions tmux/formater.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,21 +295,31 @@ func (f *Formater) currentRef() string {
return fmt.Sprintf("%s%s%s", f.Styles.Clear, f.Styles.Branch, branch)
}

// formatFlag formats a flag with or without count based on the flags_without_count option
func (f *Formater) formatFlag(style, symbol string, count int) string {
// appendFlag appends a flag to the flags slice based on configuration options
func (f *Formater) appendFlag(flags []string, style, symbol string, count int) []string {
if count == 0 {
return flags
}

if f.Options.FlagsWithoutCount {
return fmt.Sprintf("%s%s", style, symbol)
// When flags_without_count is true, show symbol only (empty string if symbol is empty)
if symbol == "" {
return flags
}
return append(flags, fmt.Sprintf("%s%s", style, symbol))
}
return fmt.Sprintf("%s%s%d", style, symbol, count)

// When flags_without_count is false, show symbol + count, or just count if symbol is empty
return append(flags, fmt.Sprintf("%s%s%d", style, symbol, count))
}

func (f *Formater) flags() string {
var flags []string
if f.st.IsClean {
if f.st.NumStashed != 0 && f.Symbols.Stashed != "" {
flags = append(flags, f.formatFlag(f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed))
}
// For stashed in clean state, handle empty symbols properly
flags = f.appendFlag(flags, f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed)

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

if f.st.NumStaged != 0 && f.Symbols.Staged != "" {
flags = append(flags, f.formatFlag(f.Styles.Staged, f.Symbols.Staged, f.st.NumStaged))
}

if f.st.NumConflicts != 0 && f.Symbols.Conflict != "" {
flags = append(flags, f.formatFlag(f.Styles.Conflict, f.Symbols.Conflict, f.st.NumConflicts))
}

if f.st.NumModified != 0 && f.Symbols.Modified != "" {
flags = append(flags, f.formatFlag(f.Styles.Modified, f.Symbols.Modified, f.st.NumModified))
}

if f.st.NumStashed != 0 && f.Symbols.Stashed != "" {
flags = append(flags, f.formatFlag(f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed))
}

if f.st.NumUntracked != 0 && f.Symbols.Untracked != "" {
flags = append(flags, f.formatFlag(f.Styles.Untracked, f.Symbols.Untracked, f.st.NumUntracked))
}
// For all other flags, handle empty symbols properly
flags = f.appendFlag(flags, f.Styles.Staged, f.Symbols.Staged, f.st.NumStaged)
flags = f.appendFlag(flags, f.Styles.Conflict, f.Symbols.Conflict, f.st.NumConflicts)
flags = f.appendFlag(flags, f.Styles.Modified, f.Symbols.Modified, f.st.NumModified)
flags = f.appendFlag(flags, f.Styles.Stashed, f.Symbols.Stashed, f.st.NumStashed)
flags = f.appendFlag(flags, f.Styles.Untracked, f.Symbols.Untracked, f.st.NumUntracked)

if len(flags) > 0 {
return f.Styles.Clear + strings.Join(flags, " ")
Expand Down
Loading
Loading