oh-my-posh/segment_virtualenv.go

41 lines
730 B
Go
Raw Normal View History

2019-03-13 04:14:30 -07:00
package main
import "fmt"
type venv struct {
props *properties
env environmentInfo
venvName string
}
const (
//PythonIcon used to indicate a Python virtualenv is active
PythonIcon Property = "python_icon"
)
func (v *venv) string() string {
return fmt.Sprintf("%s %s", v.props.getString(PythonIcon, "PYTHON:"), v.venvName)
}
func (v *venv) init(props *properties, env environmentInfo) {
v.props = props
v.env = env
}
func (v *venv) enabled() bool {
venvVars := []string{
"VIRTUAL_ENV",
"CONDA_ENV_PATH",
"CONDA_DEFAULT_ENV",
}
var venv string
for _, venvVar := range venvVars {
venv = v.env.getenv(venvVar)
if venv != "" {
v.venvName = base(venv, v.env)
return true
}
}
return false
}