Skip to content

Commit 1606e24

Browse files
authored
Issue 77/count insertions deletions (#83)
* tmux: cosmetics * bump gitstatus to v0.6.0 * testscript: set TestWork to true * Add Insertions/Deletions to Symbols and Styles * Show insertions/deletions if 'stats' is in the layout * Add Test_stats * Update README.md
1 parent 9dc9823 commit 1606e24

File tree

7 files changed

+166
-38
lines changed

7 files changed

+166
-38
lines changed

README.md

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,30 @@
2929
- **shell-agnostic**. Does not rely on shell-features so works with all of them
3030
- **customizable**. Colors, symbols and layout are configurable
3131

32+
---
33+
34+
- [Prerequisites](#prerequisites)
35+
- [Installing](#installing)
36+
- [Binary release](#binary-release)
37+
- [Homebrew (tap) macOS and linux, amd64 and arm64](#homebrew-tap-macos-and-linux-amd64-and-arm64)
38+
- [AUR](#aur)
39+
- [From source](#from-source)
40+
- [Getting started](#getting-started)
41+
- [Customizing](#customizing)
42+
- [Symbols](#symbols)
43+
- [Styles](#styles)
44+
- [Layout components](#layout-components)
45+
- [Additional options](#additional-options)
46+
- [Troubleshooting](#troubleshooting)
47+
- [Gitmux takes too long to refresh?](#gitmux-takes-too-long-to-refresh)
48+
- [Contributing](#contributing)
49+
- [License: MIT](#license-mit)
50+
51+
3252

3353
## Prerequisites
3454

35-
Works with all decently recent [tmux](https://github.com/tmux/tmux) versions.
55+
Works with all reasonably recent [tmux](https://github.com/tmux/tmux) versions (2.1+)
3656

3757
## Installing
3858

@@ -92,18 +112,22 @@ tmux:
92112
untracked: ''
93113
stashed: ''
94114
clean:
115+
insertions: Σ
116+
deletions: Δ
95117
styles:
96118
clear: '#[fg=default]'
97119
state: '#[fg=red,bold]'
98120
branch: '#[fg=white,bold]'
99121
remote: '#[fg=cyan]'
122+
divergence: '#[fg=default]'
100123
staged: '#[fg=green,bold]'
101124
conflict: '#[fg=red,bold]'
102125
modified: '#[fg=red,bold]'
103126
untracked: '#[fg=magenta,bold]'
104127
stashed: '#[fg=cyan,bold]'
105128
clean: '#[fg=green,bold]'
106-
divergence: '#[fg=default]'
129+
insertions: '#[fg=green]'
130+
deletions: '#[fg=red]'
107131
layout: [branch, .., remote-branch, divergence, ' - ', flags]
108132
options:
109133
branch_max_len: 0
@@ -112,11 +136,11 @@ tmux:
112136
113137
First, save the default configuration to a new file:
114138
115-
gitmux -printcfg > .gitmux.conf
139+
gitmux -printcfg > $HOME/.gitmux.conf
116140
117-
Modify the line in `.tmux.conf`, passing the path of the configuration file as argument to `gitmux` via the `-cfg` flag
141+
Modify the line you've added to `.tmux.conf`, passing the path of the configuration file as argument to `gitmux` via the `-cfg` flag
118142

119-
set -g status-right '#(gitmux -cfg .gitmux.conf "#{pane_current_path}")'
143+
set -g status-right '#(gitmux -cfg $HOME/.gitmux.conf "#{pane_current_path}")'
120144

121145
Open `.gitmux.conf` and modify it, replacing symbols, styles and layout to suit your needs.
122146

@@ -135,16 +159,18 @@ The `symbols` section describes the symbols `gitmux` prints for the various comp
135159

136160
```yaml
137161
symbols:
138-
branch: '⎇ ' # Shown before a branch
139-
hashprefix: ':' # Shown before a Git hash (in 'detached HEAD' state)
140-
ahead: ↑· # Shown before the 'ahead count' when local and remote branch diverge
141-
behind: ↓· # Shown before the 'behind count' when local/remote branch diverge
142-
staged: '● ' # Shown before the 'staged' files count
143-
conflict: '✖ ' # Shown before the 'conflicts' count
144-
modified: '✚ ' # Shown before the 'modified' files count
145-
untracked: '… ' # Shown before the 'untracked' files count
146-
stashed: '⚑ ' # Shown before the 'stash' count
147-
clean: ✔ # Shown when the working tree is clean (empty staging area)
162+
branch: '⎇ ' # Shown before a branch
163+
hashprefix: ':' # Shown before a Git hash (in 'detached HEAD' state)
164+
ahead: ↑· # Shown before the 'ahead count' when local and remote branch diverge
165+
behind: ↓· # Shown before the 'behind count' when local/remote branch diverge
166+
staged: '● ' # Shown before the 'staged' files count
167+
conflict: '✖ ' # Shown before the 'conflicts' count
168+
modified: '✚ ' # Shown before the 'modified' files count
169+
untracked: '… ' # Shown before the 'untracked' files count
170+
stashed: '⚑ ' # Shown before the 'stash' count
171+
insertions: Σ # Shown before the count of insertied lines (stats sections).
172+
deletions: Δ # Shown before the count of deletions lines (stats sections).
173+
clean: ✔ # Shown when the working tree is clean (empty staging area)
148174
```
149175

150176

@@ -165,6 +191,8 @@ See [`tmux` styles reference](https://man7.org/linux/man-pages/man1/tmux.1.html#
165191
modified: '#[fg=red,bold]' # Style of the 'modified' files count
166192
untracked: '#[fg=magenta,bold]' # Style of the 'modified' files count
167193
stashed: '#[fg=cyan,bold]' # Style of the 'stash' entries count
194+
insertions: '#[fg=green]' # Style of the 'inserted lines' count
195+
deletions: '#[fg=red]' # Style of the 'deleted lines' count
168196
clean: '#[fg=green,bold]' # Style of the 'clean' symbol
169197
```
170198

@@ -203,9 +231,11 @@ This is the list of the possible components of the `layout`:
203231
| `divergence` | divergence local/remote branch, if any | `↓·2↑·1` |
204232
| `remote` | alias for `remote-branch` followed by `divergence` | `origin/main ↓·2↑·1` |
205233
| `flags` | Symbols representing the working tree state | `✚ 1 ⚑ 1 … 2` |
234+
| `stats` | Insertions/deletions (lines). Disabled by deafult | `Σ56 Δ21` |
206235
| any string `foo` | Any other string is directly shown | `foo` |
207236

208237

238+
209239
Some example layouts:
210240

211241
- default layout:
@@ -214,14 +244,17 @@ Some example layouts:
214244
layout: [branch, .., remote-branch, divergence, " - ", flags]
215245
```
216246

217-
- some more minimal layouts:
247+
- some examples layouts:
218248

219249
```yaml
220250
layout: [branch, divergence, " - ", flags]
221251
```
222252
```yaml
223253
layout: [flags, " ", branch]
224254
```
255+
```yaml
256+
layout: [branch, "|", flags, "|", stats]
257+
```
225258

226259

227260
### Additional options

config_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func TestScripts(t *testing.T) {
2626
return nil
2727
},
2828
UpdateScripts: *updateGolden,
29+
TestWork: true,
2930
}
3031
if err := gotooltest.Setup(&params); err != nil {
3132
t.Errorf("gotooltest.Setup error: %v", err)

go.mod

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
module github.com/arl/gitmux
22

3-
go 1.15
3+
go 1.20
44

55
require (
6-
github.com/arl/gitstatus v0.5.1
7-
github.com/rogpeppe/go-internal v1.8.1
8-
github.com/stretchr/testify v1.7.0 // indirect
6+
github.com/arl/gitstatus v0.6.0
7+
github.com/rogpeppe/go-internal v1.9.0
98
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
109
)
10+
11+
require (
12+
github.com/kr/pretty v0.1.0 // indirect
13+
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e // indirect
14+
github.com/stretchr/testify v1.7.0 // indirect
15+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
16+
)

go.sum

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/arl/gitstatus v0.5.1 h1:1PkVmVGXpmY0ibzJv4HDw8brFUoKHLVmEmKBN+XIAmU=
2-
github.com/arl/gitstatus v0.5.1/go.mod h1:/lYgp44CnFS2PqmWUuE6mDArpIJizmpE6j5XgzBZ/AI=
1+
github.com/arl/gitstatus v0.6.0 h1:y6DOdk20wHDKRZaQ5cuYNTrwRts8TXAOs8nxxpfrQts=
2+
github.com/arl/gitstatus v0.6.0/go.mod h1:qDNPAKa1vROZfzauCeHLxF4mciRLcluP+d2/a+bcxFo=
33
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
44
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
55
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@@ -11,17 +11,15 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgc
1111
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
1212
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1313
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
14-
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
15-
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
14+
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
15+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
1616
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
17-
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
1817
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
1918
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
19+
golang.org/x/exp v0.0.0-20230210204819-062eb4c674ab h1:628ME69lBm9C6JY2wXhAph/yjN3jezx1z7BIDLUwxjo=
2020
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2121
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
2222
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
23-
gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
24-
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
2523
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2624
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
2725
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

testdata/default.output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ cmp output output.golden
3333

3434
-- .gitignore --
3535
.gitignore
36-
gopath
36+
.gopath
3737
gitmux
3838
gitmux.exe
3939
.tmp

tmux/formater.go

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,29 @@ type symbols struct {
3737
Untracked string // Untracked is the string shown before the count of untracked files.
3838
Stashed string // Stashed is the string shown before the count of stash entries.
3939
Clean string // Clean is the string shown when the working tree is clean.
40+
41+
Insertions string // Insertions is the string shown before the count of inserted lines.
42+
Deletions string // Deletions is the string shown before the count of deleted lines.
4043
}
4144

4245
type styles struct {
43-
Clear string // Clear is the style string that clears all styles.
44-
State string // State is the style string printed before eventual special state.
45-
Branch string // Branch is the style string printed before the local branch.
46-
Remote string // Remote is the style string printed before the upstream branch.
47-
Staged string // Staged is the style string printed before the staged files count.
48-
Conflict string // Conflict is the style string printed before the conflict count.
49-
Modified string // Modified is the style string printed before the modified files count.
50-
Untracked string // Untracked is the style string printed before the untracked files count.
51-
Stashed string // Stashed is the style string printed before the stash entries count.
52-
Clean string // Clean is the style string printed before the clean symbols.
46+
Clear string // Clear is the style string that clears all styles.
47+
48+
State string // State is the style string printed before eventual special state.
49+
Branch string // Branch is the style string printed before the local branch.
50+
Remote string // Remote is the style string printed before the upstream branch.
51+
5352
Divergence string // Divergence is the style string printed before divergence count/symbols.
53+
54+
Staged string // Staged is the style string printed before the staged files count.
55+
Conflict string // Conflict is the style string printed before the conflict count.
56+
Modified string // Modified is the style string printed before the modified files count.
57+
Untracked string // Untracked is the style string printed before the untracked files count.
58+
Stashed string // Stashed is the style string printed before the stash entries count.
59+
Clean string // Clean is the style string printed before the clean symbols.
60+
61+
Insertions string // Insertions is the style string printed before the count of inserted lines.
62+
Deletions string // Deletions is the style string printed before the count of deleted lines.
5463
}
5564

5665
const (
@@ -94,6 +103,9 @@ var DefaultCfg = Config{
94103
Ahead: "↑·",
95104
Behind: "↓·",
96105
HashPrefix: ":",
106+
107+
Insertions: "Σ",
108+
Deletions: "Δ",
97109
},
98110
Styles: styles{
99111
Clear: "#[fg=default]",
@@ -107,6 +119,8 @@ var DefaultCfg = Config{
107119
Untracked: "#[fg=magenta,bold]",
108120
Stashed: "#[fg=cyan,bold]",
109121
Clean: "#[fg=green,bold]",
122+
Insertions: "#[fg=green]",
123+
Deletions: "#[fg=red]",
110124
},
111125
Layout: []string{"branch", "..", "remote-branch", "divergence", " - ", "flags"},
112126
Options: options{
@@ -190,6 +204,8 @@ func (f *Formater) format() {
190204
f.divergence()
191205
case "flags":
192206
f.flags()
207+
case "stats":
208+
f.stats()
193209
default:
194210
f.clear()
195211
f.b.WriteString(item)
@@ -312,3 +328,20 @@ func (f *Formater) flags() {
312328
f.b.WriteString(strings.Join(flags, " "))
313329
}
314330
}
331+
332+
func (f *Formater) stats() {
333+
stats := make([]string, 0, 2)
334+
335+
if f.st.Insertions != 0 {
336+
stats = append(stats, fmt.Sprintf("%s%s%d", f.Styles.Insertions, f.Symbols.Insertions, f.st.Insertions))
337+
}
338+
339+
if f.st.Deletions != 0 {
340+
stats = append(stats, fmt.Sprintf("%s%s%d", f.Styles.Deletions, f.Symbols.Deletions, f.st.Deletions))
341+
}
342+
343+
if len(stats) != 0 {
344+
f.clear()
345+
f.b.WriteString(strings.Join(stats, " "))
346+
}
347+
}

tmux/formater_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,3 +523,60 @@ func TestFormat(t *testing.T) {
523523
})
524524
}
525525
}
526+
527+
func Test_stats(t *testing.T) {
528+
tests := []struct {
529+
name string
530+
layout []string
531+
insertions, deletions int
532+
want string
533+
}{
534+
{
535+
name: "nothing",
536+
want: "",
537+
},
538+
{
539+
name: "insertions",
540+
insertions: 12,
541+
want: "StyleClear" + "StyleInsertionsSymbolInsertions12",
542+
},
543+
{
544+
name: "deletions",
545+
deletions: 12,
546+
want: "StyleClear" + "StyleDeletionsSymbolDeletions12",
547+
},
548+
{
549+
name: "insertions and deletions",
550+
insertions: 1,
551+
deletions: 2,
552+
want: "StyleClear" + "StyleInsertionsSymbolInsertions1" + " " + "StyleDeletionsSymbolDeletions2",
553+
},
554+
}
555+
for _, tt := range tests {
556+
t.Run(tt.name, func(t *testing.T) {
557+
f := &Formater{
558+
Config: Config{
559+
Styles: styles{
560+
Clear: "StyleClear",
561+
Deletions: "StyleDeletions",
562+
Insertions: "StyleInsertions",
563+
},
564+
Symbols: symbols{
565+
Deletions: "SymbolDeletions",
566+
Insertions: "SymbolInsertions",
567+
},
568+
Layout: []string{"stats"},
569+
},
570+
st: &gitstatus.Status{
571+
Insertions: tt.insertions,
572+
Deletions: tt.deletions,
573+
},
574+
}
575+
f.stats()
576+
577+
if got := f.b.String(); got != tt.want {
578+
t.Errorf("got:\n%s\n\nwant:\n%s\n", got, tt.want)
579+
}
580+
})
581+
}
582+
}

0 commit comments

Comments
 (0)