Skip to content

Commit

Permalink
feat: fix when not displaying upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
lnu committed Jan 2, 2021
1 parent e48ec5f commit 0707831
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/segment_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,14 @@ func (g *git) string() string {
}
enableHyperlink := g.props.getBool(EnableHyperlink, false)
buffer := new(bytes.Buffer)

// url
upstream := replaceAllString("/.*", g.repo.upstream, "")
g.repo.url = g.getGitCommandOutput("remote", "get-url", upstream)

// branchName
if g.repo.upstream != "" && g.props.getBool(DisplayUpstreamIcon, false) {
fmt.Fprintf(buffer, "%s", g.getUpstreamSymbol())
fmt.Fprintf(buffer, "%s", g.getUpstreamSymbol(g.repo.url))
}
if enableHyperlink {
url := strings.Replace(g.repo.url, ".git", "", -1)
Expand Down Expand Up @@ -193,16 +198,14 @@ func (g *git) getStatusDetailString(status *gitStatus, color, icon Property, def
return status.string(prefix, foregroundColor)
}

func (g *git) getUpstreamSymbol() string {
upstream := replaceAllString("/.*", g.repo.upstream, "")
g.repo.url = g.getGitCommandOutput("remote", "get-url", upstream)
if strings.Contains(g.repo.url, "github") {
func (g *git) getUpstreamSymbol(url string) string {
if strings.Contains(url, "github") {
return g.props.getString(GithubIcon, "\uF408 ")
}
if strings.Contains(g.repo.url, "gitlab") {
if strings.Contains(url, "gitlab") {
return g.props.getString(GitlabIcon, "\uF296 ")
}
if strings.Contains(g.repo.url, "bitbucket") {
if strings.Contains(url, "bitbucket") {
return g.props.getString(BitbucketIcon, "\uF171 ")
}
return g.props.getString(GitIcon, "\uE5FB ")
Expand Down

0 comments on commit 0707831

Please sign in to comment.