forked from justjanne/powerline-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
segment-virtualenv.go
46 lines (41 loc) · 926 Bytes
/
segment-virtualenv.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"os"
"path"
"gopkg.in/ini.v1"
pwl "github.com/justjanne/powerline-go/powerline"
)
func segmentVirtualEnv(p *powerline) []pwl.Segment {
var env string
if env == "" {
env, _ = os.LookupEnv("VIRTUAL_ENV")
if env != "" {
cfg, err := ini.Load(path.Join(env, "pyvenv.cfg"))
if err == nil {
env = cfg.Section("").Key("prompt").String()
}
}
}
if env == "" {
env, _ = os.LookupEnv("CONDA_ENV_PATH")
}
if env == "" {
env, _ = os.LookupEnv("CONDA_DEFAULT_ENV")
}
if env == "" {
env, _ = os.LookupEnv("PYENV_VERSION")
}
if env == "" {
return []pwl.Segment{}
}
envName := path.Base(env)
if p.cfg.VenvNameSizeLimit > 0 && len(envName) > p.cfg.VenvNameSizeLimit {
envName = p.symbols.VenvIndicator
}
return []pwl.Segment{{
Name: "venv",
Content: escapeVariables(p, envName),
Foreground: p.theme.VirtualEnvFg,
Background: p.theme.VirtualEnvBg,
}}
}