Skip to content

Commit f5424ea

Browse files
authored
Merge pull request #389 from scop/feat/virtualenv-improvements
feat: virtualenv improvements
2 parents df3475d + ef5e672 commit f5424ea

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

segment-virtualenv.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@ package main
33
import (
44
"os"
55
"path"
6+
"strings"
67

78
"gopkg.in/ini.v1"
89

910
pwl "github.com/justjanne/powerline-go/powerline"
1011
)
1112

1213
func segmentVirtualEnv(p *powerline) []pwl.Segment {
13-
var env string
14+
env := os.Getenv("VIRTUAL_ENV_PROMPT")
15+
if strings.HasPrefix(env, "(") && strings.HasSuffix(env, ") ") {
16+
env = strings.TrimPrefix(env, "(")
17+
env = strings.TrimSuffix(env, ") ")
18+
}
1419
if env == "" {
15-
env, _ = os.LookupEnv("VIRTUAL_ENV")
16-
if env != "" {
17-
cfg, err := ini.Load(path.Join(env, "pyvenv.cfg"))
20+
venv, _ := os.LookupEnv("VIRTUAL_ENV")
21+
if venv != "" {
22+
cfg, err := ini.Load(path.Join(venv, "pyvenv.cfg"))
1823
if err == nil {
1924
env = cfg.Section("").Key("prompt").String()
2025
}
26+
if env == "" {
27+
env = venv
28+
}
2129
}
2230
}
2331
if env == "" {

0 commit comments

Comments
 (0)