Skip to content

Commit

Permalink
Add git stashed segment
Browse files Browse the repository at this point in the history
  • Loading branch information
breml committed Nov 7, 2017
1 parent f42ad60 commit 8aa025f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var symbolTemplates = map[string]Symbols{
RepoNotStaged: "\u270E",
RepoUntracked: "+",
RepoConflicted: "\u273C",
RepoStashed: "\u2691",
},
"patched": {
Lock: "\uE0A2",
Expand All @@ -28,6 +29,7 @@ var symbolTemplates = map[string]Symbols{
RepoNotStaged: "\u270E",
RepoUntracked: "+",
RepoConflicted: "\u273C",
RepoStashed: "\u2691",
},
"flat": {
RepoDetached: "\u2693",
Expand All @@ -37,6 +39,7 @@ var symbolTemplates = map[string]Symbols{
RepoNotStaged: "\u270E",
RepoUntracked: "+",
RepoConflicted: "\u273C",
RepoStashed: "\u2691",
},
}

Expand Down Expand Up @@ -131,6 +134,8 @@ var themes = map[string]Theme{
GitUntrackedBg: 52,
GitConflictedFg: 15,
GitConflictedBg: 9,
GitStashedFg: 15,
GitStashedBg: 20,

VirtualEnvFg: 00,
VirtualEnvBg: 35, // a mid-tone green
Expand Down Expand Up @@ -463,6 +468,8 @@ var themes = map[string]Theme{
GitUntrackedBg: 15,
GitConflictedFg: 9,
GitConflictedBg: 15,
GitStashedFg: 15,
GitStashedBg: 20,

VirtualEnvFg: 35, // a mid-tone green
VirtualEnvBg: 254,
Expand Down
2 changes: 2 additions & 0 deletions generatePreview.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ git init;
touch file1;
git add .;
git commit -m "commit";
echo "test">file1;
git stash;

export HOME=/tmp/home/

Expand Down
10 changes: 10 additions & 0 deletions segment-git.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type repoStats struct {
notStaged int
staged int
conflicted int
stashed int
}

func (r repoStats) dirty() bool {
Expand All @@ -39,6 +40,7 @@ func (r repoStats) addToPowerline(p *powerline) {
addRepoStatsSegment(p, r.notStaged, p.symbolTemplates.RepoNotStaged, p.theme.GitNotStagedFg, p.theme.GitNotStagedBg)
addRepoStatsSegment(p, r.untracked, p.symbolTemplates.RepoUntracked, p.theme.GitUntrackedFg, p.theme.GitUntrackedBg)
addRepoStatsSegment(p, r.conflicted, p.symbolTemplates.RepoConflicted, p.theme.GitConflictedFg, p.theme.GitConflictedBg)
addRepoStatsSegment(p, r.stashed, p.symbolTemplates.RepoStashed, p.theme.GitStashedFg, p.theme.GitStashedBg)
}

var branchRegex = regexp.MustCompile(`^## (?P<local>\S+?)(\.{3}(?P<remote>\S+?)( \[(ahead (?P<ahead>\d+)(, )?)?(behind (?P<behind>\d+))?])?)?$`)
Expand Down Expand Up @@ -166,6 +168,14 @@ func segmentGit(p *powerline) {
background = p.theme.RepoCleanBg
}

out, err = runGitCommand("git", "stash", "list")
if err != nil {
return
}
if len(out) > 0 {
stats.stashed = len(strings.Split(out, "\n")) - 1
}

p.appendSegment("git-branch", segment{
content: branch,
foreground: foreground,
Expand Down
3 changes: 3 additions & 0 deletions themes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Symbols struct {
RepoNotStaged string
RepoUntracked string
RepoConflicted string
RepoStashed string
}

type Theme struct {
Expand Down Expand Up @@ -84,6 +85,8 @@ type Theme struct {
GitUntrackedBg uint8
GitConflictedFg uint8
GitConflictedBg uint8
GitStashedFg uint8
GitStashedBg uint8

VirtualEnvFg uint8
VirtualEnvBg uint8
Expand Down
2 changes: 2 additions & 0 deletions themes/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"GitUntrackedBg": 52,
"GitConflictedFg": 15,
"GitConflictedBg": 9,
"GitStashedFg": 15,
"GitStashedBg": 20,
"VirtualEnvFg": 0,
"VirtualEnvBg": 35,
"PerlbrewFg": 0,
Expand Down

0 comments on commit 8aa025f

Please sign in to comment.