Skip to content

Commit

Permalink
git ignores global config gitexcludes/.git/config/ignore #295
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vgropp committed Mar 11, 2021
1 parent b51cc19 commit 5b7d2b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
11 changes: 11 additions & 0 deletions environment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import "runtime"

func homeEnvName() string {
env := "HOME"
if runtime.GOOS == "windows" {
env = "USERPROFILE"
}
return env
}
11 changes: 6 additions & 5 deletions segment-git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
7 changes: 1 addition & 6 deletions segment-kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path"
"path/filepath"
"regexp"
"runtime"
"strings"

"gopkg.in/yaml.v2"
Expand All @@ -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) {
Expand Down

0 comments on commit 5b7d2b2

Please sign in to comment.