From 5b7d2b2d167d985935896f6f9eb6447292db18ca Mon Sep 17 00:00:00 2001 From: Volker Gropp Date: Thu, 11 Mar 2021 21:43:24 +0100 Subject: [PATCH] git ignores global config gitexcludes/.git/config/ignore #295 The main culprit was the init `make([]string, len(env))` which added 3 zero entries to the slice which broke HOME/USERPROFILE for git status. Used USERPROFILE hack from segement-kube for windows in this case as well, as HOME is not set in gitbash/windows. --- environment.go | 11 +++++++++++ segment-git.go | 11 ++++++----- segment-kube.go | 7 +------ 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 environment.go diff --git a/environment.go b/environment.go new file mode 100644 index 00000000..e9007a15 --- /dev/null +++ b/environment.go @@ -0,0 +1,11 @@ +package main + +import "runtime" + +func homeEnvName() string { + env := "HOME" + if runtime.GOOS == "windows" { + env = "USERPROFILE" + } + return env +} diff --git a/segment-git.go b/segment-git.go index 6837a2d5..8693695d 100644 --- a/segment-git.go +++ b/segment-git.go @@ -88,14 +88,15 @@ func groupDict(pattern *regexp.Regexp, haystack string) map[string]string { } var gitProcessEnv = func() []string { - home, _ := os.LookupEnv("HOME") + homeEnv := homeEnvName() + home, _ := os.LookupEnv(homeEnv) path, _ := os.LookupEnv("PATH") env := map[string]string{ - "LANG": "C", - "HOME": home, - "PATH": path, + "LANG": "C", + homeEnv: home, + "PATH": path, } - result := make([]string, len(env)) + result := make([]string, 0) for key, value := range env { result = append(result, fmt.Sprintf("%s=%s", key, value)) } diff --git a/segment-kube.go b/segment-kube.go index b595bd0a..d9db0470 100644 --- a/segment-kube.go +++ b/segment-kube.go @@ -8,7 +8,6 @@ import ( "path" "path/filepath" "regexp" - "runtime" "strings" "gopkg.in/yaml.v2" @@ -31,11 +30,7 @@ type KubeConfig struct { } func homePath() string { - env := "HOME" - if runtime.GOOS == "windows" { - env = "USERPROFILE" - } - return os.Getenv(env) + return os.Getenv(homeEnvName()) } func readKubeConfig(config *KubeConfig, path string) (err error) {