From e866c6bf7633ec9c0059c5c1c2407a651ea95f82 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sat, 4 Dec 2021 10:26:30 +0100 Subject: [PATCH] feat(python): add virtual env name to template properties --- docs/docs/segment-python.md | 1 + docs/docs/segment-session.md | 2 +- src/segment_python.go | 13 +++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/docs/segment-python.md b/docs/docs/segment-python.md index 13bd1f81..7c4eaa4d 100644 --- a/docs/docs/segment-python.md +++ b/docs/docs/segment-python.md @@ -44,6 +44,7 @@ properties below. Defaults to `{{ .Full }}` ## Template Properties +- `.Venv`: `string` - the virtual environment name (if present) - `.Full`: `string` - the full version - `.Major`: `string` - is the major version - `.Minor`: `string` - is the minor version diff --git a/docs/docs/segment-session.md b/docs/docs/segment-session.md index f0067415..fcb0b92b 100644 --- a/docs/docs/segment-session.md +++ b/docs/docs/segment-session.md @@ -13,7 +13,7 @@ Show the current user and host name. ```json { "type": "session", - "style": "diamond", + "style": "diamond", "foreground": "#ffffff", "background": "#c386f1", "leading_diamond": "\uE0B6", diff --git a/src/segment_python.go b/src/segment_python.go index c36010ed..203c2d02 100644 --- a/src/segment_python.go +++ b/src/segment_python.go @@ -4,7 +4,8 @@ import "fmt" type python struct { language - venvName string + + Venv string } const ( @@ -13,14 +14,14 @@ const ( ) func (p *python) string() string { - if p.venvName == "" { + if p.Venv == "" { return p.language.string() } version := p.language.string() if version == "" { - return p.venvName + return p.Venv } - return fmt.Sprintf("%s %s", p.venvName, version) + return fmt.Sprintf("%s %s", p.Venv, version) } func (p *python) init(props properties, env environmentInfo) { @@ -67,14 +68,14 @@ func (p *python) loadContext() { venv = p.language.env.getenv(venvVar) name := base(venv, p.language.env) if p.canUseVenvName(name) { - p.venvName = name + p.Venv = name break } } } func (p *python) inContext() bool { - return p.venvName != "" + return p.Venv != "" } func (p *python) canUseVenvName(name string) bool {