Skip to content

Commit

Permalink
refactor: replace git icons
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Oct 16, 2020
1 parent db818b5 commit dd86c48
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 166 deletions.
36 changes: 18 additions & 18 deletions segment_git.go
Expand Up @@ -119,26 +119,26 @@ func (g *git) string() string {
}
// if ahead, print with symbol
if g.repo.ahead > 0 {
fmt.Fprintf(buffer, " %s%d", g.props.getString(BranchAheadIcon, "+"), g.repo.ahead)
fmt.Fprintf(buffer, " %s%d", g.props.getString(BranchAheadIcon, "\uF176"), g.repo.ahead)
}
// if behind, print with symbol
if g.repo.behind > 0 {
fmt.Fprintf(buffer, " %s%d", g.props.getString(BranchBehindIcon, "-"), g.repo.behind)
fmt.Fprintf(buffer, " %s%d", g.props.getString(BranchBehindIcon, "\uF175"), g.repo.behind)
}
if g.repo.behind == 0 && g.repo.ahead == 0 && g.repo.upstream != "" {
fmt.Fprintf(buffer, " %s", g.props.getString(BranchIdenticalIcon, "="))
fmt.Fprintf(buffer, " %s", g.props.getString(BranchIdenticalIcon, "\uF0C9"))
} else if g.repo.upstream == "" {
fmt.Fprintf(buffer, " %s", g.props.getString(BranchGoneIcon, "!="))
fmt.Fprintf(buffer, " %s", g.props.getString(BranchGoneIcon, "\u2262"))
}
staging := g.repo.staging.string(g.props.getString(LocalStagingIcon, "~"))
working := g.repo.working.string(g.props.getString(LocalWorkingIcon, "#"))
staging := g.repo.staging.string(g.props.getString(LocalStagingIcon, "\uF046"))
working := g.repo.working.string(g.props.getString(LocalWorkingIcon, "\uF044"))
fmt.Fprint(buffer, staging)
if staging != "" && working != "" {
fmt.Fprint(buffer, g.props.getString(StatusSeparatorIcon, " |"))
}
fmt.Fprint(buffer, working)
if g.props.getBool(DisplayStashCount, false) && g.repo.stashCount != "" {
fmt.Fprintf(buffer, " %s%s", g.props.getString(StashCountIcon, ""), g.repo.stashCount)
fmt.Fprintf(buffer, " %s%s", g.props.getString(StashCountIcon, "\uF692"), g.repo.stashCount)
}
return buffer.String()
}
Expand All @@ -153,15 +153,15 @@ func (g *git) getUpstreamSymbol() string {
upstream := upstreamRegex.ReplaceAllString(g.repo.upstream, "")
url := g.getGitCommandOutput("remote", "get-url", upstream)
if strings.Contains(url, "github") {
return g.props.getString(GithubIcon, "GITHUB")
return g.props.getString(GithubIcon, "\uF408 ")
}
if strings.Contains(url, "gitlab") {
return g.props.getString(GitlabIcon, "GITLAB")
return g.props.getString(GitlabIcon, "\uF296 ")
}
if strings.Contains(url, "bitbucket") {
return g.props.getString(BitbucketIcon, "BITBUCKET")
return g.props.getString(BitbucketIcon, "\uF171 ")
}
return g.props.getString(GitIcon, "GIT")
return g.props.getString(GitIcon, "\uE5FB ")
}

func (g *git) setGitStatus() {
Expand All @@ -187,7 +187,7 @@ func (g *git) getGitCommandOutput(args ...string) string {
}

func (g *git) getGitHEADContext(ref string) string {
branchIcon := g.props.getString(BranchIcon, "BRANCH:")
branchIcon := g.props.getString(BranchIcon, "\uE0A0")
if ref == "" {
ref = g.getPrettyHEADName()
} else {
Expand All @@ -199,27 +199,27 @@ func (g *git) getGitHEADContext(ref string) string {
onto := g.getGitRefFileSymbolicName("rebase-merge/onto")
step := g.getGitFileContents("rebase-merge/msgnum")
total := g.getGitFileContents("rebase-merge/end")
icon := g.props.getString(RebaseIcon, "REBASE:")
icon := g.props.getString(RebaseIcon, "\uE728 ")
return fmt.Sprintf("%s%s%s onto %s%s (%s/%s) at %s", icon, branchIcon, origin, branchIcon, onto, step, total, ref)
}
if g.hasGitFolder("rebase-apply") {
head := g.getGitFileContents("rebase-apply/head-name")
origin := strings.Replace(head, "refs/heads/", "", 1)
step := g.getGitFileContents("rebase-apply/next")
total := g.getGitFileContents("rebase-apply/last")
icon := g.props.getString(RebaseIcon, "REBASING:")
icon := g.props.getString(RebaseIcon, "\uE728 ")
return fmt.Sprintf("%s%s%s (%s/%s) at %s", icon, branchIcon, origin, step, total, ref)
}
// merge
if g.hasGitFile("MERGE_HEAD") {
mergeHEAD := g.getGitRefFileSymbolicName("MERGE_HEAD")
icon := g.props.getString(MergeIcon, "MERGING:")
icon := g.props.getString(MergeIcon, "\uE727 ")
return fmt.Sprintf("%s%s%s into %s", icon, branchIcon, mergeHEAD, ref)
}
// cherry-pick
if g.hasGitFile("CHERRY_PICK_HEAD") {
sha := g.getGitRefFileSymbolicName("CHERRY_PICK_HEAD")
icon := g.props.getString(CherryPickIcon, "CHERRY PICK:")
icon := g.props.getString(CherryPickIcon, "\uE29B ")
return fmt.Sprintf("%s%s onto %s", icon, sha, ref)
}
return ref
Expand Down Expand Up @@ -249,11 +249,11 @@ func (g *git) getPrettyHEADName() string {
// check for tag
ref := g.getGitCommandOutput("describe", "--tags", "--exact-match")
if ref != "" {
return fmt.Sprintf("%s%s", g.props.getString(TagIcon, "TAG:"), ref)
return fmt.Sprintf("%s%s", g.props.getString(TagIcon, "\uF412"), ref)
}
// fallback to commit
ref = g.getGitCommandOutput("rev-parse", "--short", "HEAD")
return fmt.Sprintf("%s%s", g.props.getString(CommitIcon, "COMMIT:"), ref)
return fmt.Sprintf("%s%s", g.props.getString(CommitIcon, "\uF417"), ref)
}

func (g *git) parseGitStats(output []string, working bool) *gitStatus {
Expand Down
18 changes: 9 additions & 9 deletions segment_git_test.go
Expand Up @@ -86,7 +86,7 @@ func setupHEADContextEnv(context *detachedContext) *git {
}

func TestGetGitDetachedCommitHash(t *testing.T) {
want := "COMMIT:lalasha1"
want := "\uf417lalasha1"
context := &detachedContext{
currentCommit: "lalasha1",
}
Expand All @@ -96,7 +96,7 @@ func TestGetGitDetachedCommitHash(t *testing.T) {
}

func TestGetGitHEADContextTagName(t *testing.T) {
want := "TAG:lalasha1"
want := "\uf412lalasha1"
context := &detachedContext{
currentCommit: "whatever",
tagName: "lalasha1",
Expand All @@ -107,7 +107,7 @@ func TestGetGitHEADContextTagName(t *testing.T) {
}

func TestGetGitHEADContextRebaseMerge(t *testing.T) {
want := "REBASE:BRANCH:cool-feature-bro onto BRANCH:main (2/3) at COMMIT:whatever"
want := "\ue728 \ue0a0cool-feature-bro onto \ue0a0main (2/3) at \uf417whatever"
context := &detachedContext{
currentCommit: "whatever",
rebase: "true",
Expand All @@ -123,7 +123,7 @@ func TestGetGitHEADContextRebaseMerge(t *testing.T) {
}

func TestGetGitHEADContextRebaseApply(t *testing.T) {
want := "REBASING:BRANCH:cool-feature-bro (2/3) at COMMIT:whatever"
want := "\ue728 \ue0a0cool-feature-bro (2/3) at \uf417whatever"
context := &detachedContext{
currentCommit: "whatever",
rebase: "true",
Expand All @@ -138,7 +138,7 @@ func TestGetGitHEADContextRebaseApply(t *testing.T) {
}

func TestGetGitHEADContextRebaseUnknown(t *testing.T) {
want := "COMMIT:whatever"
want := "\uf417whatever"
context := &detachedContext{
currentCommit: "whatever",
rebase: "true",
Expand All @@ -149,7 +149,7 @@ func TestGetGitHEADContextRebaseUnknown(t *testing.T) {
}

func TestGetGitHEADContextCherryPickOnBranch(t *testing.T) {
want := "CHERRY PICK:pickme onto BRANCH:main"
want := "\ue29b pickme onto \ue0a0main"
context := &detachedContext{
currentCommit: "whatever",
branchName: "main",
Expand All @@ -162,7 +162,7 @@ func TestGetGitHEADContextCherryPickOnBranch(t *testing.T) {
}

func TestGetGitHEADContextCherryPickOnTag(t *testing.T) {
want := "CHERRY PICK:pickme onto TAG:v3.4.6"
want := "\ue29b pickme onto \uf412v3.4.6"
context := &detachedContext{
currentCommit: "whatever",
tagName: "v3.4.6",
Expand All @@ -175,7 +175,7 @@ func TestGetGitHEADContextCherryPickOnTag(t *testing.T) {
}

func TestGetGitHEADContextMerge(t *testing.T) {
want := "MERGING:BRANCH:feat into BRANCH:main"
want := "\ue727 \ue0a0feat into \ue0a0main"
context := &detachedContext{
merge: true,
mergeHEAD: "feat",
Expand All @@ -186,7 +186,7 @@ func TestGetGitHEADContextMerge(t *testing.T) {
}

func TestGetGitHEADContextMergeTag(t *testing.T) {
want := "MERGING:BRANCH:feat into TAG:v3.4.6"
want := "\ue727 \ue0a0feat into \uf412v3.4.6"
context := &detachedContext{
tagName: "v3.4.6",
merge: true,
Expand Down
11 changes: 1 addition & 10 deletions themes/agnoster.json
Expand Up @@ -40,16 +40,7 @@
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#193549",
"background": "#95ffa4",
"properties": {
"branch_icon": "",
"branch_identical_icon": "",
"branch_ahead_icon": "",
"branch_behind_icon": "",
"branch_gone_icon": "",
"local_working_icon": "",
"local_staged_icon": ""
}
"background": "#95ffa4"
},
{
"type": "python",
Expand Down
11 changes: 1 addition & 10 deletions themes/agnosterplus.json
Expand Up @@ -52,16 +52,7 @@
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#193549",
"background": "#95ffa4",
"properties": {
"branch_icon": "",
"branch_identical_icon": "",
"branch_ahead_icon": "",
"branch_behind_icon": "",
"branch_gone_icon": "",
"local_working_icon": "",
"local_staged_icon": ""
}
"background": "#95ffa4"
}
]
}
Expand Down
11 changes: 1 addition & 10 deletions themes/aliens.json
Expand Up @@ -32,16 +32,7 @@
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#193549",
"background": "#95ffa4",
"properties": {
"branch_icon": "",
"branch_identical_icon": "",
"branch_ahead_icon": "",
"branch_behind_icon": "",
"branch_gone_icon": "",
"local_working_icon": "",
"local_staged_icon": ""
}
"background": "#95ffa4"
},
{
"type": "python",
Expand Down
11 changes: 1 addition & 10 deletions themes/avit.json
Expand Up @@ -17,16 +17,7 @@
{
"type": "git",
"style": "plain",
"foreground": "#C2C206",
"properties": {
"branch_icon": "",
"branch_identical_icon": "",
"branch_ahead_icon": "",
"branch_behind_icon": "",
"branch_gone_icon": "",
"local_working_icon": "",
"local_staged_icon": ""
}
"foreground": "#C2C206"
},
{
"type": "root",
Expand Down
7 changes: 0 additions & 7 deletions themes/darkblood.json
Expand Up @@ -20,13 +20,6 @@
"style": "plain",
"foreground": "#ffffff",
"properties": {
"branch_icon": "",
"branch_identical_icon": "",
"branch_ahead_icon": "",
"branch_behind_icon": "",
"branch_gone_icon": "",
"local_working_icon": "",
"local_staged_icon": "",
"prefix": "<#CB4B16>[</>",
"postfix": "<#CB4B16>]</>"
}
Expand Down
10 changes: 3 additions & 7 deletions themes/emodipt.json
Expand Up @@ -34,14 +34,10 @@
"style": "plain",
"foreground": "#F3C267",
"properties": {
"branch_icon": "🚦 ",
"branch_icon": "\u1F6A6 ",
"display_status": true,
"branch_identical_icon": "",
"branch_ahead_icon": "",
"branch_behind_icon": "",
"branch_gone_icon": "",
"local_working_icon": "",
"local_staged_icon": ""
"branch_identical_icon": "\uF14A",
"branch_gone_icon": "\u274E"
}
},
{
Expand Down
7 changes: 0 additions & 7 deletions themes/fish.json
Expand Up @@ -46,13 +46,6 @@
"foreground": "#ffffff",
"background": "#007ACC",
"properties": {
"branch_icon": "",
"branch_identical_icon": "",
"branch_ahead_icon": "",
"branch_behind_icon": "",
"branch_gone_icon": "",
"local_working_icon": "",
"local_staged_icon": "",
"prefix": "<#ffffff></> ",
"postfix": " "
}
Expand Down
7 changes: 0 additions & 7 deletions themes/honukai.json
Expand Up @@ -32,13 +32,6 @@
"style": "plain",
"foreground": "#B8B80A",
"properties": {
"branch_icon": "",
"branch_identical_icon": "",
"branch_ahead_icon": "",
"branch_behind_icon": "",
"branch_gone_icon": "",
"local_working_icon": "",
"local_staged_icon": "",
"prefix": "<#ffffff>on git:</>"
}
}
Expand Down
22 changes: 1 addition & 21 deletions themes/jandedobbeleer.json
Expand Up @@ -46,25 +46,8 @@
"foreground": "#193549",
"background": "#fffb38",
"properties": {
"branch_icon": "",
"branch_identical_icon": "",
"branch_ahead_icon": "",
"branch_behind_icon": "",
"branch_gone_icon": "",
"local_working_icon": "",
"local_staged_icon": "",
"rebase_icon": "",
"cherry_pick_icon": "",
"detached_icon": "",
"tag_icon": "",
"display_stash_count": true,
"stash_count_icon": "\uF692 ",
"merge_icon": "\uE726 ",
"display_upstream_icon": true,
"github_icon": "\uE709",
"bitbucket_icon": "\uE703",
"gitlab_icon": "\uE296",
"git_icon": "\uE702"
"display_upstream_icon": true
}
},
{
Expand All @@ -75,9 +58,6 @@
"background": "#f36943",
"properties": {
"battery_icon": "",
"discharging_icon": "\uE231 ",
"charging_icon": "\uE234 ",
"charged_icon": "\uE22F ",
"color_background": true,
"charged_color": "#4caf50",
"charging_color": "#40c4ff",
Expand Down
7 changes: 0 additions & 7 deletions themes/lambda.json
Expand Up @@ -26,13 +26,6 @@
"style": "plain",
"foreground": "#B80101",
"properties": {
"branch_icon": "",
"branch_identical_icon": "",
"branch_ahead_icon": "",
"branch_behind_icon": "",
"branch_gone_icon": "",
"local_working_icon": "",
"local_staged_icon": "",
"prefix": " <#F5F5F5>git:</>"
}
}
Expand Down
11 changes: 1 addition & 10 deletions themes/paradox.json
Expand Up @@ -40,16 +40,7 @@
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#193549",
"background": "#95ffa4",
"properties": {
"branch_icon": "",
"branch_identical_icon": "",
"branch_ahead_icon": "",
"branch_behind_icon": "",
"branch_gone_icon": "",
"local_working_icon": "",
"local_staged_icon": ""
}
"background": "#95ffa4"
},
{
"type": "python",
Expand Down

0 comments on commit dd86c48

Please sign in to comment.