Skip to content

Commit

Permalink
feat(git): allow to exclude repo's from status fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Jan 26, 2023
1 parent 4033c6f commit 51fd45d
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 30 deletions.
4 changes: 4 additions & 0 deletions src/platform/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,10 @@ func (env *Shell) DirMatchesOneOf(dir string, regexes []string) (match bool) {
}

func dirMatchesOneOf(dir, home, goos string, regexes []string) bool {
if len(regexes) == 0 {
return false
}

if goos == WINDOWS {
dir = strings.ReplaceAll(dir, "\\", "/")
home = strings.ReplaceAll(home, "\\", "/")
Expand Down
10 changes: 10 additions & 0 deletions src/segments/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func (s *GitStatus) add(code string) {
const (
// FetchStatus fetches the status of the repository
FetchStatus properties.Property = "fetch_status"
// IgnoreStatus allows to ignore certain repo's for status information
IgnoreStatus properties.Property = "ignore_status"
// FetchStashCount fetches the stash count
FetchStashCount properties.Property = "fetch_stash_count"
// FetchWorktreeCount fetches the worktree count
Expand Down Expand Up @@ -161,6 +163,9 @@ func (g *Git) Enabled() bool {
}

displayStatus := g.props.GetBool(FetchStatus, false)
if g.shouldIgnoreStatus() {
displayStatus = false
}
if displayStatus {
g.setGitStatus()
g.setGitHEADContext()
Expand Down Expand Up @@ -357,6 +362,11 @@ func (g *Git) hasWorktree(gitdir *platform.FileInfo) bool {
return false
}

func (g *Git) shouldIgnoreStatus() bool {
list := g.props.GetStringArray(IgnoreStatus, []string{})
return g.env.DirMatchesOneOf(g.realDir, list)
}

func (g *Git) setBranchStatus() {
getBranchStatus := func() string {
if g.Ahead > 0 && g.Behind > 0 {
Expand Down
2 changes: 2 additions & 0 deletions src/segments/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/properties"

"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)

const (
Expand Down Expand Up @@ -52,6 +53,7 @@ func TestEnabledInWorkingDirectory(t *testing.T) {
env.On("PathSeparator").Return("/")
env.On("Home").Return("/Users/posh")
env.On("Getenv", poshGitEnv).Return("")
env.On("DirMatchesOneOf", mock2.Anything, mock2.Anything).Return(false)
g := &Git{
scm: scm{
env: env,
Expand Down
124 changes: 94 additions & 30 deletions themes/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@
"type": "string",
"title": "Display Mode",
"description": "Determines whether the segment is displayed always or only if a file matching the extensions are present in the current folder",
"enum": ["always", "files", "environment", "context"],
"enum": [
"always",
"files",
"environment",
"context"
],
"default": "context"
},
"missing_command_text": {
Expand Down Expand Up @@ -134,7 +139,11 @@
}
},
"then": {
"required": ["type", "alignment", "segments"],
"required": [
"type",
"alignment",
"segments"
],
"title": "Prompt definition, contains 1 or more segments to render"
}
},
Expand All @@ -147,7 +156,10 @@
}
},
"then": {
"required": ["type", "segments"],
"required": [
"type",
"segments"
],
"title": "RPrompt definition, contains 1 or more segments to render to the right of the cursor"
}
},
Expand All @@ -168,7 +180,10 @@
"type": "string",
"title": "Block overflow",
"description": "https://ohmyposh.dev/docs/configuration/block#overflow",
"enum": ["break", "hide"],
"enum": [
"break",
"hide"
],
"default": ""
}
}
Expand All @@ -180,14 +195,20 @@
"type": "string",
"title": "Block type",
"description": "https://ohmyposh.dev/docs/configuration/block#type",
"enum": ["prompt", "rprompt"],
"enum": [
"prompt",
"rprompt"
],
"default": "prompt"
},
"alignment": {
"type": "string",
"title": "Block alignment",
"description": "https://ohmyposh.dev/docs/configuration/block#alignment",
"enum": ["left", "right"],
"enum": [
"left",
"right"
],
"default": "left"
},
"newline": {
Expand All @@ -212,7 +233,10 @@
"title": "A segment",
"description": "https://ohmyposh.dev/docs/configuration/segment",
"default": {},
"required": ["type", "style"],
"required": [
"type",
"style"
],
"properties": {
"type": {
"type": "string",
Expand Down Expand Up @@ -288,7 +312,12 @@
"description": "https://ohmyposh.dev/docs/configuration/segment#style",
"anyOf": [
{
"enum": ["plain", "powerline", "diamond", "accordion"]
"enum": [
"plain",
"powerline",
"diamond",
"accordion"
]
},
{
"type": "string"
Expand Down Expand Up @@ -323,20 +352,23 @@
"type": "string",
"title": "Templates Logic",
"description": "https://ohmyposh.dev/docs/configuration/segment#templates",
"enum": ["first_match", "join"]
},
"max_cols": {
"type": "integer",
"title": "if the terminal width exceeds this value, the segment will be hidden",
"description": "https://ohmyposh.dev/docs/configuration/segment#max_cols",
"default": 0
},
"min_cols": {
"type": "integer",
"title": "if the terminal width is inferior than this value, the segment will be hidden",
"description": "https://ohmyposh.dev/docs/configuration/segment#min_cols",
"default": 0
},
"enum": [
"first_match",
"join"
]
},
"max_cols": {
"type": "integer",
"title": "if the terminal width exceeds this value, the segment will be hidden",
"description": "https://ohmyposh.dev/docs/configuration/segment#max_cols",
"default": 0
},
"min_cols": {
"type": "integer",
"title": "if the terminal width is inferior than this value, the segment will be hidden",
"description": "https://ohmyposh.dev/docs/configuration/segment#min_cols",
"default": 0
},
"properties": {
"type": "object",
"title": "Segment Properties, used to change behavior/displaying",
Expand Down Expand Up @@ -503,7 +535,11 @@
"title": "Source",
"description": "https://ohmyposh.dev/docs/az#properties",
"default": "first_match",
"enum": ["first_match", "cli", "pwsh"]
"enum": [
"first_match",
"cli",
"pwsh"
]
}
}
}
Expand Down Expand Up @@ -945,6 +981,15 @@
"title": "Ignore submodules",
"description": "Ignore changes to submodules when looking for changes",
"default": {}
},
"ignore_status": {
"type": "array",
"title": "Ignore fetching status in these repo's",
"description": "Ignore fetching status for certain repo's, uses the same logic as the exclude_folders property",
"default": [],
"items": {
"type": "string"
}
}
}
}
Expand Down Expand Up @@ -2016,7 +2061,11 @@
"title": "units",
"description": "Units of measurement. Available values are standard (kelvin), metric (celsius), and imperial (fahrenheit). Default is standard",
"default": "standard",
"enum": ["standard", "metric", "imperial"]
"enum": [
"standard",
"metric",
"imperial"
]
},
"http_timeout": {
"$ref": "#/definitions/http_timeout"
Expand Down Expand Up @@ -2631,7 +2680,11 @@
"type": "string",
"title": "Use Stack GHC",
"description": "Get the GHC version used by Stack. Will decrease performance. Boolean indicating whether stack ghc was used available in template as .StackGhc",
"enum": ["always", "package", "never"],
"enum": [
"always",
"package",
"never"
],
"default": "never"
}
}
Expand Down Expand Up @@ -2818,7 +2871,10 @@
"type": "string",
"title": "Preferred Executable",
"description": "The preferred executable to use when fetching the version.",
"enum": ["lua", "luajit"],
"enum": [
"lua",
"luajit"
],
"default": "lua"
}
}
Expand Down Expand Up @@ -2941,7 +2997,9 @@
{
"if": {
"properties": {
"type": { "const": "gitversion" }
"type": {
"const": "gitversion"
}
}
},
"then": {
Expand All @@ -2952,7 +3010,9 @@
{
"if": {
"properties": {
"type": { "const": "mercurial" }
"type": {
"const": "mercurial"
}
}
},
"then": {
Expand All @@ -2975,7 +3035,9 @@
]
}
},
"required": ["blocks"],
"required": [
"blocks"
],
"properties": {
"final_space": {
"type": "boolean",
Expand Down Expand Up @@ -3027,7 +3089,9 @@
}
}
},
"required": ["tips"]
"required": [
"tips"
]
}
},
"transient_prompt": {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/segments/git.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ You can set the following properties to `true` to enable fetching additional inf
| Name | Type | Description |
| --------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `fetch_status` | `boolean` | fetch the local changes - defaults to `false` |
| `ignore_status` | `[]string` | do not fetch status for these repo's. Uses the repo's root folder and same logic as the [exclude_folders][exclude_folders] property |
| `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 |
Expand Down Expand Up @@ -191,3 +192,4 @@ Local changes use the following syntax:
[submodules]: https://git-scm.com/docs/git-status#Documentation/git-status.txt---ignore-submodulesltwhengt
[kraken-ref]: https://www.gitkraken.com/invite/nQmDPR9D
[text]: text.mdx
[exclude_folders]: /docs/configuration/segment#include--exclude-folders

0 comments on commit 51fd45d

Please sign in to comment.