Skip to content
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
6 changes: 6 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[codespell]
skip = vendor,testdata,node_modules,dist
ignore-regex = .*cspell:disable-line.*

# vim: filetype=toml

17 changes: 17 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: codespell
on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'
workflow_dispatch:
jobs:
codespell:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- uses: codespell-project/actions-codespell@v2

1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ linters:
- gocritic
- gosec
- importas
- misspell
- nilerr
- gofumpt

Expand Down
72 changes: 49 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,33 @@ var (
version = "dev" // populated by goreleaser
commit = "none" // populated by goreleaser
date = "unknown" // populated by goreleaser
configPath = flag.String("config", "", "")
promptPrefix = flag.String("prompt-prefix", " \ue0a0 ", "")
promptSuffix = flag.String("prompt-suffix", "", "")
aheadFormat = flag.String("ahead-format", "↑[%d]", "")
behindFormat = flag.String("behind-format", "↓[%d]", "")
divergedFormat = flag.String("diverged-format", "↕ ↑[%d] ↓[%d]", "")
noUpstreamRemoteFormat = flag.String("no-upstream-remote-format", " → %s/%s", "")
colorDisabled = flag.Bool("color-disabled", false, "disable all color in prompt string")
colorClean = flag.String("color-clean", "green", "")
colorConflict = flag.String("color-conflict", "yellow", "")
colorDirty = flag.String("color-dirty", "red", "")
colorUntracked = flag.String("color-untracked", "magenta", "")
colorNoUpstream = flag.String("color-no-upstream", "bright-black", "")
colorMerging = flag.String("color-merging", "blue", "")
versionFlag = flag.Bool("version", false, "version for git-prompt-string")
configPath = flag.String("config", "", "The filepath of the git-prompt-string toml configuration.")
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 .")
promptSuffix = flag.String("prompt-suffix", "", "A suffix that is added to the end of the prompt.")
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.")
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.")
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.")
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.")
colorDisabled = flag.Bool("color-disabled", false, "Disable all colors in the prompt.")
colorClean = flag.String("color-clean", "green", "The color of the prompt when the working directory is clean.\n")
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.")
colorDirty = flag.String("color-dirty", "red", "The color of the prompt when the working directory has changes\nthat have not yet been committed.")
colorUntracked = flag.String("color-untracked", "magenta", "The color of the prompt when there are untracked files in the\nworking directory.")
colorNoUpstream = flag.String("color-no-upstream", "bright-black", "The color of the prompt when there is no remote upstream branch.\n")
colorMerging = flag.String("color-merging", "blue", "The color of the prompt during a merge, rebase, cherry-pick,\nrevert, or bisect.")
versionFlag = flag.Bool("version", false, "Print version information for git-prompt-string.")
)

func header() string {
var sb strings.Builder
sb.WriteString("\n")
sb.WriteString("git-prompt-string: a shell agnostic git prompt written in Go.\n")
sb.WriteString("https://github.com/mikesmithgh/git-prompt-string\n")
sb.WriteString("\n")
return sb.String()
}

func main() {
// TODO: check if git is installed?
cfg := config.GPSConfig{
PromptPrefix: *promptPrefix,
PromptSuffix: *promptSuffix,
Expand All @@ -48,13 +56,34 @@ func main() {
NoUpstreamRemoteFormat: *noUpstreamRemoteFormat,
ColorDisabled: *colorDisabled,
ColorClean: *colorClean,
ColorConflict: *colorConflict,
ColorDelta: *colorDelta,
ColorDirty: *colorDirty,
ColorUntracked: *colorUntracked,
ColorNoUpstream: *colorNoUpstream,
ColorMerging: *colorMerging,
}

flag.Usage = func() {
w := flag.CommandLine.Output()

var sb strings.Builder

sb.WriteString(header())
sb.WriteString("Usage:")
sb.WriteString("\n")
sb.WriteString("git-prompt-string [flags]")
sb.WriteString("\n\n")
sb.WriteString("Flags can be prefixed with either - or --. For example, -version and")
sb.WriteString("\n")
sb.WriteString("--version are both valid flags.")
sb.WriteString("\n\n")
sb.WriteString("Flags:")
sb.WriteString("\n")
fmt.Fprint(w, sb.String())

flag.PrintDefaults()
}

flag.Parse()

var gpsConfig string
Expand Down Expand Up @@ -114,8 +143,8 @@ func main() {
cfg.ColorDisabled = colorDisabled
case "color-clean":
cfg.ColorClean = f.Value.String()
case "color-conflict":
cfg.ColorConflict = f.Value.String()
case "color-delta":
cfg.ColorDelta = f.Value.String()
case "color-dirty":
cfg.ColorDirty = f.Value.String()
case "color-untracked":
Expand All @@ -132,10 +161,7 @@ func main() {
}

if *versionFlag {
fmt.Println()
fmt.Println("git-prompt-string")
fmt.Println("https://github.com/mikesmithgh/git-prompt-string")
fmt.Println()
fmt.Print(header())
fmt.Printf("Version: %s\n", version)
fmt.Printf("Commit: %s\n", commit)
fmt.Printf("BuildDate: %s\n", date)
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type GPSConfig struct {
NoUpstreamRemoteFormat string `toml:"no_upstream_remote_format"`
ColorDisabled bool `toml:"color_disabled"`
ColorClean string `toml:"color_clean"`
ColorConflict string `toml:"color_conflict"`
ColorDelta string `toml:"color_delta"`
ColorDirty string `toml:"color_dirty"`
ColorUntracked string `toml:"color_untracked"`
ColorNoUpstream string `toml:"color_no_upstream"`
Expand Down
8 changes: 4 additions & 4 deletions pkg/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,16 @@ func (g *GitRepo) BranchStatus(cfg config.GPSConfig) (string, string, error) {
}

if ahead > 0 {
statusColor, err = color.Color(strings.Split(cfg.ColorConflict, " ")...)
statusColor, err = color.Color(strings.Split(cfg.ColorDelta, " ")...)
if err != nil {
util.ErrMsg("color conflict", err)
util.ErrMsg("color delta ahead", err)
}
status = fmt.Sprintf(cfg.AheadFormat, ahead)
}
if behind > 0 {
statusColor, err = color.Color(strings.Split(cfg.ColorConflict, " ")...)
statusColor, err = color.Color(strings.Split(cfg.ColorDelta, " ")...)
if err != nil {
util.ErrMsg("color conflict", err)
util.ErrMsg("color delta behind", err)
}
status = fmt.Sprintf(cfg.BehindFormat, behind)
}
Expand Down
2 changes: 1 addition & 1 deletion testdata/configs/color_overrides.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
color_clean='#e6ee04'
color_no_upstream="fg:black bg:white"
color_dirty="bg:#b30559"
color_conflict="fg:#fcb728"
color_delta="fg:#fcb728"
color_untracked="fg:#ff0000 bg:#16f2aa"
color_merging="bg:#ccccff magenta"