Skip to content

Commit 595c9fd

Browse files
authored
Issue 82/comment default config (#87)
* Remove _ prefix to variables * Update README.md: align with default config * -printcfg shows commented configuration * Remove unused formater.go * Move config-related in config.go * tmux: remove DefaultCfg variable The default configuration is now defined in an embedded file with comments. Fixes #82
1 parent 4decaa8 commit 595c9fd

File tree

6 files changed

+144
-96
lines changed

6 files changed

+144
-96
lines changed

.gitmux.yml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
tmux:
2+
# The symbols section defines the symbols printed before specific elements
3+
# of Git status displayed in tmux status string.
4+
symbols:
5+
# current branch name.
6+
branch: ""
7+
# Git SHA1 hash (in 'detached' state).
8+
hashprefix: ":"
9+
# 'ahead count' when local and remote branch diverged.
10+
ahead: ↑·
11+
# 'behind count' when local and remote branch diverged.
12+
behind: ↓·
13+
# count of files in the staging area.
14+
staged: ""
15+
# count of files in conflicts.
16+
conflict: ""
17+
# count of modified files.
18+
modified: ""
19+
# count of untracked files.
20+
untracked: ""
21+
# count of stash entries.
22+
stashed: ""
23+
# count of inserted lines (stats section).
24+
insertions: Σ
25+
# count of deleted lines (stats section).
26+
deletions: Δ
27+
# Shown when the working tree is clean.
28+
clean:
29+
30+
# Styles are tmux format strings used to specify text colors and attributes
31+
# of Git status elements. See the STYLES section of tmux man page.
32+
# https://man7.org/linux/man-pages/man1/tmux.1.html#STYLES.
33+
styles:
34+
# Clear previous style.
35+
clear: "#[fg=default]"
36+
# Special tree state strings such as [rebase], [merge], etc.
37+
state: "#[fg=red,bold]"
38+
# Local branch name
39+
branch: "#[fg=white,bold]"
40+
# Remote branch name
41+
remote: "#[fg=cyan]"
42+
# 'divergence' counts
43+
divergence: "#[fg=yellow]"
44+
# 'staged' count
45+
staged: "#[fg=green,bold]"
46+
# 'conflicts' count
47+
conflict: "#[fg=red,bold]"
48+
# 'modified' count
49+
modified: "#[fg=red,bold]"
50+
# 'untracked' count
51+
untracked: "#[fg=magenta,bold]"
52+
# 'stash' count
53+
stashed: "#[fg=cyan,bold]"
54+
# 'insertions' count
55+
insertions: "#[fg=green]"
56+
# 'deletions' count
57+
deletions: "#[fg=red]"
58+
# 'clean' symbol
59+
clean: "#[fg=green,bold]"
60+
61+
# The layout section defines what components gitmux shows and the order in
62+
# which they appear on tmux status bar.
63+
#
64+
# Allowed components:
65+
# - branch: local branch name. Examples: `⎇ main`, `⎇ :345e7a0` or `[rebase]`
66+
# - remote-branch: remote branch name, for example: `origin/main`.
67+
# - divergence: divergence between local and remote branch, if any. Example: `↓·2↑·1`
68+
# - remote: alias for `remote-branch` followed by `divergence`, for example: `origin/main ↓·2↑·1`
69+
# - flags: symbols representing the working tree state, for example `✚ 1 ⚑ 1 … 2`
70+
# - stats: insertions/deletions (lines), for example`Σ56 Δ21`
71+
# - some string `foo`: any other character of string is directly shown, for example `foo` or `|`
72+
layout: [branch, " ", remote-branch, divergence, " - ", flags]
73+
74+
# Additional configuration options.
75+
options:
76+
# Maximum displayed length for local and remote branch names.
77+
branch_max_len: 0
78+
# Trim left or right end of the branch (`right` or `left`).
79+
branch_trim: right
80+
# Character indicating whether and where a branch was truncated.
81+
ellipsis:

README.md

+37-35
Original file line numberDiff line numberDiff line change
@@ -156,51 +156,54 @@ In `tmux` status bar, `gitmux` output immediately reflects the changes you make
156156

157157
### Symbols
158158

159-
The `symbols` section describes the symbols `gitmux` prints for the various components of the status string.
159+
The `symbols` section defines the symbols printed before specific elements
160+
of Git status displayed in `tmux` status string:
160161

161162
```yaml
162163
symbols:
163-
branch: '⎇ ' # Shown before a branch
164-
hashprefix: ':' # Shown before a Git hash (in 'detached HEAD' state)
165-
ahead: ↑· # Shown before the 'ahead count' when local and remote branch diverge
166-
behind: ↓· # Shown before the 'behind count' when local/remote branch diverge
167-
staged: '● ' # Shown before the 'staged' files count
168-
conflict: '✖ ' # Shown before the 'conflicts' count
169-
modified: '✚ ' # Shown before the 'modified' files count
170-
untracked: '… ' # Shown before the 'untracked' files count
171-
stashed: '⚑ ' # Shown before the 'stash' count
172-
insertions: Σ # Shown before the count of insertied lines (stats sections).
173-
deletions: Δ # Shown before the count of deletions lines (stats sections).
174-
clean: ✔ # Shown when the working tree is clean (empty staging area)
164+
branch: "⎇ " # current branch name.
165+
hashprefix: ":" # Git SHA1 hash (in 'detached' state).
166+
ahead: ↑· # 'ahead count' when local and remote branch diverged.
167+
behind: ↓· # 'behind count' when local and remote branch diverged.
168+
staged: "● " # count of files in the staging area.
169+
conflict: "✖ " # count of files in conflicts.
170+
modified: "✚ " # count of modified files.
171+
untracked: "… " # count of untracked files.
172+
stashed: "⚑ " # count of stash entries.
173+
insertions: Σ # count of inserted lines (stats section).
174+
deletions: Δ # count of deleted lines (stats section).
175+
clean: ✔ # Shown when the working tree is clean.
175176
```
176177

177178

178179
### Styles
179180

180-
Styles are tmux format strings used to specify text colors and attributes.
181-
See [`tmux` styles reference](https://man7.org/linux/man-pages/man1/tmux.1.html#STYLES).
181+
Styles are tmux format strings used to specify text colors and attributes of Git
182+
status elements.
183+
See the [`STYLES` section](https://man7.org/linux/man-pages/man1/tmux.1.html#STYLES) of `tmux` man page.
182184

183185
```yaml
184186
styles:
185-
clear: '#[fg=default]' # Style clearing previous styles (printed before each component)
186-
state: '#[fg=red,bold]' # Style of the special states strings like [rebase], [merge], etc.
187-
branch: '#[fg=white,bold]' # Style of the local branch name
188-
remote: '#[fg=cyan]' # Style of the remote branch name
189-
divergence: "#[fg=yellow]" # Style of the 'divergence' string
190-
staged: '#[fg=green,bold]' # Style of the 'staged' files count
191-
conflict: '#[fg=red,bold]' # Style of the 'conflicts' count
192-
modified: '#[fg=red,bold]' # Style of the 'modified' files count
193-
untracked: '#[fg=magenta,bold]' # Style of the 'modified' files count
194-
stashed: '#[fg=cyan,bold]' # Style of the 'stash' entries count
195-
insertions: '#[fg=green]' # Style of the 'inserted lines' count
196-
deletions: '#[fg=red]' # Style of the 'deleted lines' count
197-
clean: '#[fg=green,bold]' # Style of the 'clean' symbol
187+
clear: '#[fg=default]' # Clear previous style.
188+
state: '#[fg=red,bold]' # Special tree state strings such as [rebase], [merge], etc.
189+
branch: '#[fg=white,bold]' # Local branch name
190+
remote: '#[fg=cyan]' # Remote branch name
191+
divergence: "#[fg=yellow]" # 'divergence' counts
192+
staged: '#[fg=green,bold]' # 'staged' count
193+
conflict: '#[fg=red,bold]' # 'conflicts' count
194+
modified: '#[fg=red,bold]' # 'modified' count
195+
untracked: '#[fg=magenta,bold]' # 'untracked' count
196+
stashed: '#[fg=cyan,bold]' # 'stash' count
197+
insertions: '#[fg=green]' # 'insertions' count
198+
deletions: '#[fg=red]' # 'deletions' count
199+
clean: '#[fg=green,bold]' # 'clean' symbol
198200
```
199201

200202
### Layout components
201203

202-
The layout is a list of the components `gitmux` shows, and the order in
203-
which they appear on `tmux` status bar.
204+
The `layout` section defines what components `gitmux` shows and the order in which
205+
they appear on `tmux` status bar.
206+
204207

205208
For example, the default `gitmux` layout shows is:
206209

@@ -223,18 +226,17 @@ the remote branch, etc.
223226
But you can anyway choose to never show some components if you wish, or to present
224227
them in a different order.
225228

226-
This is the list of the possible components of the `layout`:
229+
This is the list of the possible keywords for `layout`:
227230

228-
| Layout component | Description | Example |
231+
| Layout keywords | Description | Example |
229232
| :--------------: | :------------------------------------------------- | :------------------: |
230233
| `branch` | local branch name | `main` |
231234
| `remote-branch` | remote branch name | `origin/main` |
232235
| `divergence` | divergence local/remote branch, if any | `↓·2↑·1` |
233236
| `remote` | alias for `remote-branch` followed by `divergence` | `origin/main ↓·2↑·1` |
234237
| `flags` | Symbols representing the working tree state | `✚ 1 ⚑ 1 … 2` |
235-
| `stats` | Insertions/deletions (lines). Disabled by deafult | `Σ56 Δ21` |
236-
| any string `foo` | Any other string is directly shown | `foo` |
237-
238+
| `stats` | Insertions/deletions (lines). Disabled by default | `Σ56 Δ21` |
239+
| any string `foo` | Non-keywords are shown as-is | `hello gitmux` |
238240

239241

240242
Some example layouts:

config.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
_ "embed"
5+
"fmt"
6+
7+
"github.com/arl/gitmux/tmux"
8+
"gopkg.in/yaml.v3"
9+
)
10+
11+
// Config configures output formatting.
12+
type Config struct{ Tmux tmux.Config }
13+
14+
// default config (decoded in init)
15+
var defaultCfg Config
16+
17+
//go:embed .gitmux.yml
18+
var cfgBytes []byte
19+
20+
func init() {
21+
if err := yaml.Unmarshal(cfgBytes, &defaultCfg); err != nil {
22+
panic(fmt.Sprintf("default config is invalid: %v", err))
23+
}
24+
}

formater.go

-13
This file was deleted.

gitmux.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ Options:
3030
-V prints gitmux version and exits.
3131
`
3232

33-
// Config configures output formatting.
34-
type Config struct{ Tmux tmux.Config }
35-
36-
var _defaultCfg = Config{Tmux: tmux.DefaultCfg}
37-
3833
func parseOptions() (ctx context.Context, cancel func(), dir string, dbg bool, cfg Config) {
3934
var (
4035
dbgOpt = flag.Bool("dbg", false, "")
@@ -60,13 +55,11 @@ func parseOptions() (ctx context.Context, cancel func(), dir string, dbg bool, c
6055
}
6156

6257
if *printCfgOpt {
63-
enc := yaml.NewEncoder(os.Stdout)
64-
check(enc.Encode(&_defaultCfg), *dbgOpt)
65-
enc.Close()
58+
os.Stdout.Write(cfgBytes)
6659
os.Exit(0)
6760
}
6861

69-
cfg = _defaultCfg
62+
cfg = defaultCfg
7063

7164
if *cfgOpt != "" {
7265
f, err := os.Open(*cfgOpt)

tmux/formater.go

-39
Original file line numberDiff line numberDiff line change
@@ -91,45 +91,6 @@ type options struct {
9191
Ellipsis string `yaml:"ellipsis"`
9292
}
9393

94-
// DefaultCfg is the default tmux configuration.
95-
var DefaultCfg = Config{
96-
Symbols: symbols{
97-
Branch: "⎇ ",
98-
Staged: "● ",
99-
Conflict: "✖ ",
100-
Modified: "✚ ",
101-
Untracked: "… ",
102-
Stashed: "⚑ ",
103-
Clean: "✔",
104-
Ahead: "↑·",
105-
Behind: "↓·",
106-
HashPrefix: ":",
107-
Insertions: "Σ",
108-
Deletions: "Δ",
109-
},
110-
Styles: styles{
111-
Clear: "#[fg=default]",
112-
State: "#[fg=red,bold]",
113-
Branch: "#[fg=white,bold]",
114-
Remote: "#[fg=cyan]",
115-
Divergence: "#[fg=default]",
116-
Staged: "#[fg=green,bold]",
117-
Conflict: "#[fg=red,bold]",
118-
Modified: "#[fg=red,bold]",
119-
Untracked: "#[fg=magenta,bold]",
120-
Stashed: "#[fg=cyan,bold]",
121-
Clean: "#[fg=green,bold]",
122-
Insertions: "#[fg=green]",
123-
Deletions: "#[fg=red]",
124-
},
125-
Layout: []string{"branch", " ", "remote-branch", "divergence", " - ", "flags"},
126-
Options: options{
127-
BranchMaxLen: 0,
128-
BranchTrim: dirRight,
129-
Ellipsis: "…",
130-
},
131-
}
132-
13394
// A Formater formats git status to a tmux style string.
13495
type Formater struct {
13596
Config

0 commit comments

Comments
 (0)