mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 20:39:40 -08:00
feat(python): add virtual env name to template properties
This commit is contained in:
parent
39a27b29ad
commit
e866c6bf76
|
@ -44,6 +44,7 @@ properties below. Defaults to `{{ .Full }}`
|
||||||
|
|
||||||
## Template Properties
|
## Template Properties
|
||||||
|
|
||||||
|
- `.Venv`: `string` - the virtual environment name (if present)
|
||||||
- `.Full`: `string` - the full version
|
- `.Full`: `string` - the full version
|
||||||
- `.Major`: `string` - is the major version
|
- `.Major`: `string` - is the major version
|
||||||
- `.Minor`: `string` - is the minor version
|
- `.Minor`: `string` - is the minor version
|
||||||
|
|
|
@ -13,7 +13,7 @@ Show the current user and host name.
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"type": "session",
|
"type": "session",
|
||||||
"style": "diamond",
|
"style": "diamond",
|
||||||
"foreground": "#ffffff",
|
"foreground": "#ffffff",
|
||||||
"background": "#c386f1",
|
"background": "#c386f1",
|
||||||
"leading_diamond": "\uE0B6",
|
"leading_diamond": "\uE0B6",
|
||||||
|
|
|
@ -4,7 +4,8 @@ import "fmt"
|
||||||
|
|
||||||
type python struct {
|
type python struct {
|
||||||
language
|
language
|
||||||
venvName string
|
|
||||||
|
Venv string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -13,14 +14,14 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *python) string() string {
|
func (p *python) string() string {
|
||||||
if p.venvName == "" {
|
if p.Venv == "" {
|
||||||
return p.language.string()
|
return p.language.string()
|
||||||
}
|
}
|
||||||
version := p.language.string()
|
version := p.language.string()
|
||||||
if version == "" {
|
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) {
|
func (p *python) init(props properties, env environmentInfo) {
|
||||||
|
@ -67,14 +68,14 @@ func (p *python) loadContext() {
|
||||||
venv = p.language.env.getenv(venvVar)
|
venv = p.language.env.getenv(venvVar)
|
||||||
name := base(venv, p.language.env)
|
name := base(venv, p.language.env)
|
||||||
if p.canUseVenvName(name) {
|
if p.canUseVenvName(name) {
|
||||||
p.venvName = name
|
p.Venv = name
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *python) inContext() bool {
|
func (p *python) inContext() bool {
|
||||||
return p.venvName != ""
|
return p.Venv != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *python) canUseVenvName(name string) bool {
|
func (p *python) canUseVenvName(name string) bool {
|
||||||
|
|
Loading…
Reference in a new issue