feat(git): allow adding own remote icons

resolves #3300
This commit is contained in:
Jan De Dobbeleer 2023-01-06 08:06:34 +01:00 committed by Jan De Dobbeleer
parent 6f8733eacd
commit 62a1bf96da
3 changed files with 31 additions and 15 deletions

View file

@ -72,6 +72,8 @@ const (
TagIcon properties.Property = "tag_icon"
// MergeIcon shows before the merge context
MergeIcon properties.Property = "merge_icon"
// UpstreamIcons allows to add custom upstream icons
UpstreamIcons properties.Property = "upstream_icons"
// GithubIcon shows√ when upstream is github
GithubIcon properties.Property = "github_icon"
// BitbucketIcon shows when upstream is bitbucket
@ -337,6 +339,15 @@ func (g *Git) getUpstreamIcon() string {
}
g.RawUpstreamURL = g.getRemoteURL()
g.UpstreamURL = cleanSSHURL(g.RawUpstreamURL)
// allow overrides first
custom := g.props.GetKeyValueMap(UpstreamIcons, map[string]string{})
for key, value := range custom {
if strings.Contains(g.UpstreamURL, key) {
return value
}
}
defaults := map[string]struct {
Icon properties.Property
Default string

View file

@ -598,6 +598,7 @@ func TestGitUpstream(t *testing.T) {
{Case: "Azure DevOps", Expected: "AD", Upstream: "dev.azure.com/test"},
{Case: "Azure DevOps Dos", Expected: "AD", Upstream: "test.visualstudio.com"},
{Case: "Gitstash", Expected: "G", Upstream: "gitstash.com/test"},
{Case: "My custom server", Expected: "CU", Upstream: "mycustom.server/test"},
}
for _, tc := range cases {
env := &mock.MockedEnvironment{}
@ -611,6 +612,9 @@ func TestGitUpstream(t *testing.T) {
BitbucketIcon: "BB",
AzureDevOpsIcon: "AD",
GitIcon: "G",
UpstreamIcons: map[string]string{
"mycustom.server": "CU",
},
}
g := &Git{
scm: scm{

View file

@ -67,14 +67,14 @@ You can then use the `POSH_GIT_STRING` environment variable in a [text segment][
As doing multiple git calls can slow down the prompt experience, we do not fetch information by default.
You can set the following properties to `true` to enable fetching additional information (and populate the template).
| Name | Type | Description |
| ---------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `fetch_status` | `boolean` | fetch the local changes - defaults to `false` |
| `fetch_upstream_icon` | `boolean` | fetch upstream icon - defaults to `false` |
| `fetch_bare_info` | `boolean` | fetch bare repo info - defaults to `false` |
| `untracked_modes` | `map[string]string` | map of repo's where to override the default [untracked files mode][untracked]:<ul><li>`no`</li><li>`normal`</li><li>`all`</li></ul>For example `"untracked_modes": { "/Users/me/repos/repo1": "no" }` - defaults to `normal` for all repo's. If you want to override for all repo's, use `*` to set the mode instead of the repo path |
| `ignore_submodules` | `map[string]string` | map of repo's where to change the [--ignore-submodules][submodules] flag (`none`, `untracked`, `dirty` or `all`). For example `"ignore_submodules": { "/Users/me/repos/repo1": "all" }`. If you want to override for all repo's, use `*` to set the mode instead of the repo path |
| `native_fallback` | `boolean` | when set to `true` and `git.exe` is not available when inside a WSL2 shared Windows drive, we will fallback to the native git executable to fetch data. Not all information can be displayed in this case. Defaults to `false` |
| Name | Type | Description |
| --------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `fetch_status` | `boolean` | fetch the local changes - defaults to `false` |
| `fetch_upstream_icon` | `boolean` | fetch upstream icon - defaults to `false` |
| `fetch_bare_info` | `boolean` | fetch bare repo info - defaults to `false` |
| `untracked_modes` | `map[string]string` | map of repo's where to override the default [untracked files mode][untracked]:<ul><li>`no`</li><li>`normal`</li><li>`all`</li></ul>For example `"untracked_modes": { "/Users/me/repos/repo1": "no" }` - defaults to `normal` for all repo's. If you want to override for all repo's, use `*` to set the mode instead of the repo path |
| `ignore_submodules` | `map[string]string` | map of repo's where to change the [--ignore-submodules][submodules] flag (`none`, `untracked`, `dirty` or `all`). For example `"ignore_submodules": { "/Users/me/repos/repo1": "all" }`. If you want to override for all repo's, use `*` to set the mode instead of the repo path |
| `native_fallback` | `boolean` | when set to `true` and `git.exe` is not available when inside a WSL2 shared Windows drive, we will fallback to the native git executable to fetch data. Not all information can be displayed in this case. Defaults to `false` |
### Icons
@ -104,13 +104,14 @@ You can set the following properties to `true` to enable fetching additional inf
#### Upstream
| Name | Type | Description |
| ------------------- | -------- | ---------------------------------------------------------------------------------- |
| `github_icon` | `string` | icon/text to display when the upstream is Github - defaults to `\uF408 ` |
| `gitlab_icon` | `string` | icon/text to display when the upstream is Gitlab - defaults to `\uF296 ` |
| `bitbucket_icon` | `string` | icon/text to display when the upstream is Bitbucket - defaults to `\uF171 ` |
| `azure_devops_icon` | `string` | icon/text to display when the upstream is Azure DevOps - defaults to `\uFD03 ` |
| `git_icon` | `string` | icon/text to display when the upstream is not known/mapped - defaults to `\uE5FB ` |
| Name | Type | Description |
| ------------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `github_icon` | `string` | icon/text to display when the upstream is Github - defaults to `\uF408 ` |
| `gitlab_icon` | `string` | icon/text to display when the upstream is Gitlab - defaults to `\uF296 ` |
| `bitbucket_icon` | `string` | icon/text to display when the upstream is Bitbucket - defaults to `\uF171 ` |
| `azure_devops_icon` | `string` | icon/text to display when the upstream is Azure DevOps - defaults to `\uFD03 ` |
| `git_icon` | `string` | icon/text to display when the upstream is not known/mapped - defaults to `\uE5FB ` |
| `upstream_icons` | `map[string]string` | a key, value map representing the remote URL (or a part of that URL) and icon to use in case the upstream URL contains the key. These get precedence over the standard icons |
## Template ([info][templates])