Skip to content

Commit

Permalink
Merge pull request #389 from scop/feat/virtualenv-improvements
Browse files Browse the repository at this point in the history
feat: virtualenv improvements
  • Loading branch information
justjanne authored Jun 17, 2024
2 parents df3475d + ef5e672 commit f5424ea
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions segment-virtualenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@ package main
import (
"os"
"path"
"strings"

"gopkg.in/ini.v1"

pwl "github.com/justjanne/powerline-go/powerline"
)

func segmentVirtualEnv(p *powerline) []pwl.Segment {
var env string
env := os.Getenv("VIRTUAL_ENV_PROMPT")
if strings.HasPrefix(env, "(") && strings.HasSuffix(env, ") ") {
env = strings.TrimPrefix(env, "(")
env = strings.TrimSuffix(env, ") ")
}
if env == "" {
env, _ = os.LookupEnv("VIRTUAL_ENV")
if env != "" {
cfg, err := ini.Load(path.Join(env, "pyvenv.cfg"))
venv, _ := os.LookupEnv("VIRTUAL_ENV")
if venv != "" {
cfg, err := ini.Load(path.Join(venv, "pyvenv.cfg"))
if err == nil {
env = cfg.Section("").Key("prompt").String()
}
if env == "" {
env = venv
}
}
}
if env == "" {
Expand Down

0 comments on commit f5424ea

Please sign in to comment.