Skip to content

Commit

Permalink
feat(virtualenv): look up VIRTUAL_ENV_PROMPT first
Browse files Browse the repository at this point in the history
Standard venv activation typically sets it to `(name) `. Parse that
first to avoid having to parse pyvenv.cfg.

Co-authored-by: Janne Mareike Koschinski <[email protected]>
  • Loading branch information
scop and justjanne committed Jun 17, 2024
1 parent df3475d commit 3c6ebb4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion segment-virtualenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ 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 != "" {
Expand Down

0 comments on commit 3c6ebb4

Please sign in to comment.