diff --git a/src/platform/shell.go b/src/platform/shell.go index d2031dad..5f28f359 100644 --- a/src/platform/shell.go +++ b/src/platform/shell.go @@ -416,6 +416,7 @@ func (env *Shell) HasFiles(pattern string) bool { matches, err := fs.Glob(fileSystem, pattern) if err != nil { env.Error(err) + env.Debug("false") return false } for _, match := range matches { @@ -423,8 +424,10 @@ func (env *Shell) HasFiles(pattern string) bool { if err != nil || file.IsDir() { continue } + env.Debug("true") return true } + env.Debug("false") return false } @@ -434,6 +437,7 @@ func (env *Shell) HasFilesInDir(dir, pattern string) bool { matches, err := fs.Glob(fileSystem, pattern) if err != nil { env.Error(err) + env.Debug("false") return false } hasFilesInDir := len(matches) > 0 diff --git a/src/segments/docker.go b/src/segments/docker.go index ac1308c7..53c8c247 100644 --- a/src/segments/docker.go +++ b/src/segments/docker.go @@ -60,14 +60,16 @@ func (d *Docker) Enabled() bool { // Check if there is a file named `$HOME/.docker/config.json` or `$DOCKER_CONFIG/config.json` // Return the current context if it is not empty and not `default` for _, f := range d.configFiles() { - if !d.env.HasFiles(f) { + data := d.env.FileContent(f) + if len(data) == 0 { continue } - data := d.env.FileContent(f) + var cfg DockerConfig if err := json.Unmarshal([]byte(data), &cfg); err != nil { continue } + if len(cfg.CurrentContext) > 0 && cfg.CurrentContext != "default" { d.Context = cfg.CurrentContext return true