Skip to content

Commit 626b6a5

Browse files
authored
feat: rename conflict to delta and doc cli flags (#47)
1 parent 5afd144 commit 626b6a5

File tree

7 files changed

+78
-30
lines changed

7 files changed

+78
-30
lines changed

.codespellrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[codespell]
2+
skip = vendor,testdata,node_modules,dist
3+
ignore-regex = .*cspell:disable-line.*
4+
5+
# vim: filetype=toml
6+

.github/workflows/codespell.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: codespell
2+
on:
3+
push:
4+
branches:
5+
- 'main'
6+
pull_request:
7+
branches:
8+
- 'main'
9+
workflow_dispatch:
10+
jobs:
11+
codespell:
12+
runs-on: ubuntu-22.04
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
- uses: codespell-project/actions-codespell@v2
17+

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ linters:
2121
- gocritic
2222
- gosec
2323
- importas
24-
- misspell
2524
- nilerr
2625
- gofumpt
2726

main.go

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,33 @@ var (
2020
version = "dev" // populated by goreleaser
2121
commit = "none" // populated by goreleaser
2222
date = "unknown" // populated by goreleaser
23-
configPath = flag.String("config", "", "")
24-
promptPrefix = flag.String("prompt-prefix", " \ue0a0 ", "")
25-
promptSuffix = flag.String("prompt-suffix", "", "")
26-
aheadFormat = flag.String("ahead-format", "↑[%d]", "")
27-
behindFormat = flag.String("behind-format", "↓[%d]", "")
28-
divergedFormat = flag.String("diverged-format", "↕ ↑[%d] ↓[%d]", "")
29-
noUpstreamRemoteFormat = flag.String("no-upstream-remote-format", " → %s/%s", "")
30-
colorDisabled = flag.Bool("color-disabled", false, "disable all color in prompt string")
31-
colorClean = flag.String("color-clean", "green", "")
32-
colorConflict = flag.String("color-conflict", "yellow", "")
33-
colorDirty = flag.String("color-dirty", "red", "")
34-
colorUntracked = flag.String("color-untracked", "magenta", "")
35-
colorNoUpstream = flag.String("color-no-upstream", "bright-black", "")
36-
colorMerging = flag.String("color-merging", "blue", "")
37-
versionFlag = flag.Bool("version", false, "version for git-prompt-string")
23+
configPath = flag.String("config", "", "The filepath of the git-prompt-string toml configuration.")
24+
promptPrefix = flag.String("prompt-prefix", " \ue0a0 ", "A prefix that is added to the beginning of the prompt. The\npowerline icon  is used be default. It is recommended to\nuse a Nerd Font to properly display the  (nf-pl-branch) icon.\nSee https://www.nerdfonts.com/ to download a Nerd Font. If you\ndo not want this symbol, replace the prompt prefix with \" \".\n\\ue0a0 is the unicode representation of .")
25+
promptSuffix = flag.String("prompt-suffix", "", "A suffix that is added to the end of the prompt.")
26+
aheadFormat = flag.String("ahead-format", "↑[%v]", "The format used to indicate the number of commits ahead of the\nremote branch. The %v verb represents the number of commits\nahead. One %v verb is required.")
27+
behindFormat = flag.String("behind-format", "↓[%v]", "The format used to indicate the number of commits behind the\nremote branch. The %v verb represents the number of commits\nbehind. One %v verb is required.")
28+
divergedFormat = flag.String("diverged-format", "↕ ↑[%v] ↓[%v]", "The format used to indicate the number of commits diverged\nfrom the remote branch. The first %v verb represents the number\nof commits ahead of the remote branch. The second %v verb\nrepresents the number of commits behind the remote branch. Two\n%v verbs are required.")
29+
noUpstreamRemoteFormat = flag.String("no-upstream-remote-format", " → %v/%v", "The format used to indicate when there is no remote upstream,\nbut there is still a remote branch configured. The first %v\nrepresents the remote repository. The second %v represents the\nremote branch. Two %v are required.")
30+
colorDisabled = flag.Bool("color-disabled", false, "Disable all colors in the prompt.")
31+
colorClean = flag.String("color-clean", "green", "The color of the prompt when the working directory is clean.\n")
32+
colorDelta = flag.String("color-delta", "yellow", "The color of the prompt when the local branch is ahead, behind,\nor has diverged from the remote branch.")
33+
colorDirty = flag.String("color-dirty", "red", "The color of the prompt when the working directory has changes\nthat have not yet been committed.")
34+
colorUntracked = flag.String("color-untracked", "magenta", "The color of the prompt when there are untracked files in the\nworking directory.")
35+
colorNoUpstream = flag.String("color-no-upstream", "bright-black", "The color of the prompt when there is no remote upstream branch.\n")
36+
colorMerging = flag.String("color-merging", "blue", "The color of the prompt during a merge, rebase, cherry-pick,\nrevert, or bisect.")
37+
versionFlag = flag.Bool("version", false, "Print version information for git-prompt-string.")
3838
)
3939

40+
func header() string {
41+
var sb strings.Builder
42+
sb.WriteString("\n")
43+
sb.WriteString("git-prompt-string: a shell agnostic git prompt written in Go.\n")
44+
sb.WriteString("https://github.com/mikesmithgh/git-prompt-string\n")
45+
sb.WriteString("\n")
46+
return sb.String()
47+
}
48+
4049
func main() {
41-
// TODO: check if git is installed?
4250
cfg := config.GPSConfig{
4351
PromptPrefix: *promptPrefix,
4452
PromptSuffix: *promptSuffix,
@@ -48,13 +56,34 @@ func main() {
4856
NoUpstreamRemoteFormat: *noUpstreamRemoteFormat,
4957
ColorDisabled: *colorDisabled,
5058
ColorClean: *colorClean,
51-
ColorConflict: *colorConflict,
59+
ColorDelta: *colorDelta,
5260
ColorDirty: *colorDirty,
5361
ColorUntracked: *colorUntracked,
5462
ColorNoUpstream: *colorNoUpstream,
5563
ColorMerging: *colorMerging,
5664
}
5765

66+
flag.Usage = func() {
67+
w := flag.CommandLine.Output()
68+
69+
var sb strings.Builder
70+
71+
sb.WriteString(header())
72+
sb.WriteString("Usage:")
73+
sb.WriteString("\n")
74+
sb.WriteString("git-prompt-string [flags]")
75+
sb.WriteString("\n\n")
76+
sb.WriteString("Flags can be prefixed with either - or --. For example, -version and")
77+
sb.WriteString("\n")
78+
sb.WriteString("--version are both valid flags.")
79+
sb.WriteString("\n\n")
80+
sb.WriteString("Flags:")
81+
sb.WriteString("\n")
82+
fmt.Fprint(w, sb.String())
83+
84+
flag.PrintDefaults()
85+
}
86+
5887
flag.Parse()
5988

6089
var gpsConfig string
@@ -114,8 +143,8 @@ func main() {
114143
cfg.ColorDisabled = colorDisabled
115144
case "color-clean":
116145
cfg.ColorClean = f.Value.String()
117-
case "color-conflict":
118-
cfg.ColorConflict = f.Value.String()
146+
case "color-delta":
147+
cfg.ColorDelta = f.Value.String()
119148
case "color-dirty":
120149
cfg.ColorDirty = f.Value.String()
121150
case "color-untracked":
@@ -132,10 +161,7 @@ func main() {
132161
}
133162

134163
if *versionFlag {
135-
fmt.Println()
136-
fmt.Println("git-prompt-string")
137-
fmt.Println("https://github.com/mikesmithgh/git-prompt-string")
138-
fmt.Println()
164+
fmt.Print(header())
139165
fmt.Printf("Version: %s\n", version)
140166
fmt.Printf("Commit: %s\n", commit)
141167
fmt.Printf("BuildDate: %s\n", date)

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type GPSConfig struct {
99
NoUpstreamRemoteFormat string `toml:"no_upstream_remote_format"`
1010
ColorDisabled bool `toml:"color_disabled"`
1111
ColorClean string `toml:"color_clean"`
12-
ColorConflict string `toml:"color_conflict"`
12+
ColorDelta string `toml:"color_delta"`
1313
ColorDirty string `toml:"color_dirty"`
1414
ColorUntracked string `toml:"color_untracked"`
1515
ColorNoUpstream string `toml:"color_no_upstream"`

pkg/git/repo.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,16 @@ func (g *GitRepo) BranchStatus(cfg config.GPSConfig) (string, string, error) {
227227
}
228228

229229
if ahead > 0 {
230-
statusColor, err = color.Color(strings.Split(cfg.ColorConflict, " ")...)
230+
statusColor, err = color.Color(strings.Split(cfg.ColorDelta, " ")...)
231231
if err != nil {
232-
util.ErrMsg("color conflict", err)
232+
util.ErrMsg("color delta ahead", err)
233233
}
234234
status = fmt.Sprintf(cfg.AheadFormat, ahead)
235235
}
236236
if behind > 0 {
237-
statusColor, err = color.Color(strings.Split(cfg.ColorConflict, " ")...)
237+
statusColor, err = color.Color(strings.Split(cfg.ColorDelta, " ")...)
238238
if err != nil {
239-
util.ErrMsg("color conflict", err)
239+
util.ErrMsg("color delta behind", err)
240240
}
241241
status = fmt.Sprintf(cfg.BehindFormat, behind)
242242
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
color_clean='#e6ee04'
22
color_no_upstream="fg:black bg:white"
33
color_dirty="bg:#b30559"
4-
color_conflict="fg:#fcb728"
4+
color_delta="fg:#fcb728"
55
color_untracked="fg:#ff0000 bg:#16f2aa"
66
color_merging="bg:#ccccff magenta"

0 commit comments

Comments
 (0)