mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 20:39:40 -08:00
parent
87e54cac01
commit
c23a1d6e1c
|
@ -32,25 +32,49 @@ Local changes can also shown by default using the following syntax for both the
|
||||||
"rebase_icon": " ",
|
"rebase_icon": " ",
|
||||||
"cherry_pick_icon": " ",
|
"cherry_pick_icon": " ",
|
||||||
"commit_icon": " ",
|
"commit_icon": " ",
|
||||||
"tag_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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
|
### Standard
|
||||||
|
|
||||||
- branch_icon: `string` - the icon to use in front of the git branch name
|
- branch_icon: `string` - the icon to use in front of the git branch name
|
||||||
- branch_identical_icon: `string` - the icon to display when remote and local are identical
|
- branch_identical_icon: `string` - the icon to display when remote and local are identical
|
||||||
- branch_ahead_icon: `string` - the icon to display when the local branch is ahead of its remote
|
- branch_ahead_icon: `string` - the icon to display when the local branch is ahead of its remote
|
||||||
- branch_behind_icon: `string` - the icon to display when the local branch is behind its remote
|
- branch_behind_icon: `string` - the icon to display when the local branch is behind its remote
|
||||||
|
|
||||||
|
### Status
|
||||||
|
|
||||||
|
- display_status: `boolean` - display the local changes or not
|
||||||
|
- display_stash_count: `boolean` show stash count or not
|
||||||
|
- status_separator_icon: `string` icon/text to display between staging and working area changes
|
||||||
- local_working_icon: `string` - the icon to display in front of the working area changes
|
- local_working_icon: `string` - the icon to display in front of the working area changes
|
||||||
- local_staged_icon: `string` - the icon to display in front of the staged area changes
|
- local_staged_icon: `string` - the icon to display in front of the staged area changes
|
||||||
- display_status: `boolean` - display the local changes or not
|
- stash_count_icon: `string` icon/text to display before the stash context
|
||||||
|
|
||||||
|
### HEAD context
|
||||||
|
|
||||||
|
- commit_icon: `string` - icon/text to display before the commit context (detached HEAD)
|
||||||
|
- tag_icon: `string` - icon/text to display before the tag context
|
||||||
- rebase_icon: `string` - icon/text to display before the context when in a rebase
|
- rebase_icon: `string` - icon/text to display before the context when in a rebase
|
||||||
- cherry_pick_icon: `string` - icon/text to display before the context when doing a cherry-pick
|
- cherry_pick_icon: `string` - icon/text to display before the context when doing a cherry-pick
|
||||||
- commit_icon: `string` - icon/text to display before the commit context
|
|
||||||
- tag_icon: `string` - icon/text to display before the tag context
|
|
||||||
- display_stash_count: `boolean` show stash count or not
|
|
||||||
- stash_count_icon: `string` icon/text to display before the stash context
|
|
||||||
- status_separator_icon: `string` icon/text to display between staging and working area changes
|
|
||||||
- merge_icon: `string` icon/text to display before the merge context
|
- merge_icon: `string` icon/text to display before the merge context
|
||||||
|
|
||||||
|
### Upstream context
|
||||||
|
|
||||||
|
- display_upstream_icon: `boolean` - display upstrean icon or not
|
||||||
|
- github_icon: `string` - icon/text to display when the upstream is Github
|
||||||
|
- gitlab_icon: `string` - icon/text to display when the upstream is Gitlab
|
||||||
|
- bitbucket_icon: `string` - icon/text to display when the upstream is Bitbucket
|
||||||
|
- git_icon: `string` - icon/text to display when the upstream is not known/mapped
|
||||||
|
|
|
@ -84,6 +84,16 @@ const (
|
||||||
StatusSeparatorIcon Property = "status_separator_icon"
|
StatusSeparatorIcon Property = "status_separator_icon"
|
||||||
//MergeIcon shows before the merge context
|
//MergeIcon shows before the merge context
|
||||||
MergeIcon Property = "merge_icon"
|
MergeIcon Property = "merge_icon"
|
||||||
|
//DisplayUpstreamIcon show or hide the upstream icon
|
||||||
|
DisplayUpstreamIcon Property = "display_upstream_icon"
|
||||||
|
//GithubIcon shows√ when upstream is github
|
||||||
|
GithubIcon Property = "github_icon"
|
||||||
|
//BitbucketIcon shows when upstream is bitbucket
|
||||||
|
BitbucketIcon Property = "bitbucket_icon"
|
||||||
|
//GitlabIcon shows when upstream is gitlab
|
||||||
|
GitlabIcon Property = "gitlab_icon"
|
||||||
|
//GitIcon shows when the upstream can't be identified
|
||||||
|
GitIcon Property = "git_icon"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (g *git) enabled() bool {
|
func (g *git) enabled() bool {
|
||||||
|
@ -98,6 +108,9 @@ func (g *git) string() string {
|
||||||
g.getGitStatus()
|
g.getGitStatus()
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
// branchName
|
// branchName
|
||||||
|
if g.repo.upstream != "" && g.props.getBool(DisplayUpstreamIcon, false) {
|
||||||
|
fmt.Fprintf(buffer, "%s", g.getUpstreamSymbol())
|
||||||
|
}
|
||||||
fmt.Fprintf(buffer, "%s", g.repo.HEAD)
|
fmt.Fprintf(buffer, "%s", g.repo.HEAD)
|
||||||
displayStatus := g.props.getBool(DisplayStatus, true)
|
displayStatus := g.props.getBool(DisplayStatus, true)
|
||||||
if !displayStatus {
|
if !displayStatus {
|
||||||
|
@ -134,6 +147,22 @@ func (g *git) init(props *properties, env environmentInfo) {
|
||||||
g.env = env
|
g.env = env
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *git) getUpstreamSymbol() string {
|
||||||
|
upstreamRegex := regexp.MustCompile("/.*")
|
||||||
|
upstream := upstreamRegex.ReplaceAllString(g.repo.upstream, "")
|
||||||
|
url := g.getGitCommandOutput("remote", "get-url", upstream)
|
||||||
|
if strings.Contains(url, "github") {
|
||||||
|
return g.props.getString(GithubIcon, "GITHUB")
|
||||||
|
}
|
||||||
|
if strings.Contains(url, "gitlab") {
|
||||||
|
return g.props.getString(GitlabIcon, "GITLAB")
|
||||||
|
}
|
||||||
|
if strings.Contains(url, "bitbucket") {
|
||||||
|
return g.props.getString(BitbucketIcon, "BITBUCKET")
|
||||||
|
}
|
||||||
|
return g.props.getString(GitIcon, "GIT")
|
||||||
|
}
|
||||||
|
|
||||||
func (g *git) getGitStatus() {
|
func (g *git) getGitStatus() {
|
||||||
g.repo = &gitRepo{}
|
g.repo = &gitRepo{}
|
||||||
output := g.getGitCommandOutput("status", "--porcelain", "-b", "--ignore-submodules")
|
output := g.getGitCommandOutput("status", "--porcelain", "-b", "--ignore-submodules")
|
||||||
|
|
|
@ -373,3 +373,48 @@ func TestParseGitStatsInvalidLine(t *testing.T) {
|
||||||
status := g.parseGitStats(output, false)
|
status := g.parseGitStats(output, false)
|
||||||
assert.Equal(t, expected, status)
|
assert.Equal(t, expected, status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bootstrapUpstreamTest(upstream string) *git {
|
||||||
|
env := &MockedEnvironment{}
|
||||||
|
env.On("runCommand", "git", []string{"-c", "core.quotepath=false", "-c", "color.status=false", "remote", "get-url", "origin"}).Return(upstream, nil)
|
||||||
|
props := &properties{
|
||||||
|
values: map[Property]interface{}{
|
||||||
|
GithubIcon: "GH",
|
||||||
|
GitlabIcon: "GL",
|
||||||
|
BitbucketIcon: "BB",
|
||||||
|
GitIcon: "G",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
g := &git{
|
||||||
|
env: env,
|
||||||
|
repo: &gitRepo{
|
||||||
|
upstream: "origin/main",
|
||||||
|
},
|
||||||
|
props: props,
|
||||||
|
}
|
||||||
|
return g
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetUpstreamSymbolGitHub(t *testing.T) {
|
||||||
|
g := bootstrapUpstreamTest("github.com/test")
|
||||||
|
upstreamIcon := g.getUpstreamSymbol()
|
||||||
|
assert.Equal(t, "GH", upstreamIcon)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetUpstreamSymbolGitLab(t *testing.T) {
|
||||||
|
g := bootstrapUpstreamTest("gitlab.com/test")
|
||||||
|
upstreamIcon := g.getUpstreamSymbol()
|
||||||
|
assert.Equal(t, "GL", upstreamIcon)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetUpstreamSymbolBitBucket(t *testing.T) {
|
||||||
|
g := bootstrapUpstreamTest("bitbucket.org/test")
|
||||||
|
upstreamIcon := g.getUpstreamSymbol()
|
||||||
|
assert.Equal(t, "BB", upstreamIcon)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetUpstreamSymbolGit(t *testing.T) {
|
||||||
|
g := bootstrapUpstreamTest("gitstash.com/test")
|
||||||
|
upstreamIcon := g.getUpstreamSymbol()
|
||||||
|
assert.Equal(t, "G", upstreamIcon)
|
||||||
|
}
|
||||||
|
|
|
@ -59,7 +59,12 @@
|
||||||
"tag_icon": "笠",
|
"tag_icon": "笠",
|
||||||
"display_stash_count": true,
|
"display_stash_count": true,
|
||||||
"stash_count_icon": "\uF692 ",
|
"stash_count_icon": "\uF692 ",
|
||||||
"merge_icon": "\uE726 "
|
"merge_icon": "\uE726 ",
|
||||||
|
"display_upstream_icon": true,
|
||||||
|
"github_icon": "\uE709",
|
||||||
|
"bitbucket_icon": "\uE703",
|
||||||
|
"gitlab_icon": "\uE296",
|
||||||
|
"git_icon": "\uE702"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue