diff --git a/.gitignore b/.gitignore index 9c5bf194..95588462 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ powerline-go .glide/ /.idea/ -~ + +.vscode/ diff --git a/go.mod b/go.mod index c7710492..492a40d7 100644 --- a/go.mod +++ b/go.mod @@ -8,5 +8,6 @@ require ( golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 golang.org/x/text v0.3.4 + gopkg.in/ini.v1 v1.66.4 gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index 64c91bef..8c028479 100644 --- a/go.sum +++ b/go.sum @@ -38,6 +38,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IV golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/ini.v1 v1.66.4 h1:SsAcf+mM7mRZo2nJNGt8mZCjG8ZRaNGMURJw7BsIST4= +gopkg.in/ini.v1 v1.66.4/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/segment-virtualenv.go b/segment-virtualenv.go index d9a305e3..dd21b385 100644 --- a/segment-virtualenv.go +++ b/segment-virtualenv.go @@ -4,6 +4,8 @@ import ( "os" "path" + "gopkg.in/ini.v1" + pwl "github.com/justjanne/powerline-go/powerline" ) @@ -11,6 +13,12 @@ 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")