diff --git a/segment-docker_context.go b/segment-docker_context.go index 63f640e8..be0ef7e8 100644 --- a/segment-docker_context.go +++ b/segment-docker_context.go @@ -17,15 +17,20 @@ func segmentDockerContext(p *powerline) []pwl.Segment { home, _ := os.LookupEnv("HOME") contextFolder := filepath.Join(home, ".docker", "contexts") configFile := filepath.Join(home, ".docker", "config.json") + contextEnvVar := os.Getenv("DOCKER_CONTEXT") - stat, err := os.Stat(contextFolder) - if err == nil && stat.IsDir() { - dockerConfigFile, err := ioutil.ReadFile(configFile) - if err == nil { - var dockerConfig DockerContextConfig - err = json.Unmarshal(dockerConfigFile, &dockerConfig) - if err == nil && dockerConfig.CurrentContext != "" { - context = dockerConfig.CurrentContext + if contextEnvVar != "" { + context = contextEnvVar + } else { + stat, err := os.Stat(contextFolder) + if err == nil && stat.IsDir() { + dockerConfigFile, err := ioutil.ReadFile(configFile) + if err == nil { + var dockerConfig DockerContextConfig + err = json.Unmarshal(dockerConfigFile, &dockerConfig) + if err == nil && dockerConfig.CurrentContext != "" { + context = dockerConfig.CurrentContext + } } } } @@ -37,7 +42,7 @@ func segmentDockerContext(p *powerline) []pwl.Segment { return []pwl.Segment{{ Name: "docker-context", - Content: "🐳" + context, + Content: context, Foreground: p.theme.PlEnvFg, Background: p.theme.PlEnvBg, }}