Skip to content

Commit

Permalink
Merge pull request #298 from jacobo-diaz/gitcompact
Browse files Browse the repository at this point in the history
Added a new "compact" Git mode, with less width than "fancy", and a bit more information than "simple"
  • Loading branch information
justjanne authored Mar 17, 2021
2 parents a13f33e + 889978d commit c6e1677
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,9 @@ Usage of powerline-go:
-git-disable-stats string
Comma-separated list to disable individual git statuses
(valid choices: ahead, behind, staged, notStaged, untracked, conflicted, stashed)
-git-mode string
How to display git status
(valid choices: fancy, simple)
(valid choices: fancy, compact, simple)
(default "fancy")
-hostname-only-if-ssh
Show hostname only for SSH connections
Expand Down
2 changes: 1 addition & 1 deletion args.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var args = arguments{
"git-mode",
defaults.GitMode,
commentsWithDefaults("How to display git status",
"(valid choices: fancy, simple)")),
"(valid choices: fancy, compact, simple)")),
Mode: flag.String(
"mode",
defaults.Mode,
Expand Down
28 changes: 19 additions & 9 deletions segment-git.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,28 @@ func (r repoStats) GitSegments(p *powerline) (segments []pwl.Segment) {
return
}

func addRepoStatsSymbol(nChanges int, symbol string) string {
func addRepoStatsSymbol(nChanges int, symbol string, GitMode string) string {
if nChanges > 0 {
return symbol
if GitMode == "simple" {
return symbol
} else if GitMode == "compact" {
return fmt.Sprintf(" %d%s", nChanges, symbol )
} else {
return symbol
}
}
return ""
}

func (r repoStats) GitSymbols(p *powerline) string {
var info string
info += addRepoStatsSymbol(r.ahead, p.symbols.RepoAhead)
info += addRepoStatsSymbol(r.behind, p.symbols.RepoBehind)
info += addRepoStatsSymbol(r.staged, p.symbols.RepoStaged)
info += addRepoStatsSymbol(r.notStaged, p.symbols.RepoNotStaged)
info += addRepoStatsSymbol(r.untracked, p.symbols.RepoUntracked)
info += addRepoStatsSymbol(r.conflicted, p.symbols.RepoConflicted)
info += addRepoStatsSymbol(r.stashed, p.symbols.RepoStashed)
info += addRepoStatsSymbol(r.ahead, p.symbols.RepoAhead, p.cfg.GitMode)
info += addRepoStatsSymbol(r.behind, p.symbols.RepoBehind, p.cfg.GitMode)
info += addRepoStatsSymbol(r.staged, p.symbols.RepoStaged, p.cfg.GitMode)
info += addRepoStatsSymbol(r.notStaged, p.symbols.RepoNotStaged, p.cfg.GitMode)
info += addRepoStatsSymbol(r.untracked, p.symbols.RepoUntracked, p.cfg.GitMode)
info += addRepoStatsSymbol(r.conflicted, p.symbols.RepoConflicted, p.cfg.GitMode)
info += addRepoStatsSymbol(r.stashed, p.symbols.RepoStashed, p.cfg.GitMode)
return info
}

Expand Down Expand Up @@ -266,6 +272,10 @@ func segmentGit(p *powerline) []pwl.Segment {
if stats.any() {
segments[0].Content += " " + stats.GitSymbols(p)
}
} else if p.cfg.GitMode == "compact" {
if stats.any() {
segments[0].Content += stats.GitSymbols(p)
}
} else { // fancy
segments = append(segments, stats.GitSegments(p)...)
}
Expand Down

0 comments on commit c6e1677

Please sign in to comment.