Skip to content

Commit

Permalink
Use of ini parser for the pyenv.cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
Belphegor committed Apr 21, 2022
1 parent 738cf6f commit a6d5c7a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
19 changes: 4 additions & 15 deletions segment-virtualenv.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"bufio"
"os"
"path"
"strings"

"gopkg.in/ini.v1"

pwl "github.com/justjanne/powerline-go/powerline"
)
Expand All @@ -14,21 +14,10 @@ func segmentVirtualEnv(p *powerline) []pwl.Segment {
if env == "" {
env, _ = os.LookupEnv("VIRTUAL_ENV")
if env != "" {
file, err := os.Open(path.Join(env, "pyvenv.cfg"))
cfg, err := ini.Load(path.Join(env, "pyvenv.cfg"))
if err == nil {
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
if strings.Contains(scanner.Text(), "prompt") {
var prompt = strings.Split(scanner.Text(), "=")[1]
prompt = strings.TrimSpace(prompt)
prompt = strings.Trim(prompt, "'")
env = prompt
break
}
}
env = cfg.Section("").Key("prompt").String()
}

}
}
if env == "" {
Expand Down

0 comments on commit a6d5c7a

Please sign in to comment.