mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-30 04:21:19 -08:00
fix(envvar): use template for string value
This commit is contained in:
parent
6eb9a2e492
commit
290b1a3d8c
|
@ -50,7 +50,12 @@ The segment will show when the value of the environment variable isn't empty.
|
||||||
```
|
```
|
||||||
|
|
||||||
- var_name: `string` - the name of the environment variable
|
- var_name: `string` - the name of the environment variable
|
||||||
|
- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the
|
||||||
|
properties below. Defaults to the value of the environment variable.
|
||||||
|
|
||||||
## Template Properties
|
## Template Properties
|
||||||
|
|
||||||
- `.Value`: `string` - the value of the environment variable
|
- `.Value`: `string` - the value of the environment variable
|
||||||
|
|
||||||
|
[go-text-template]: https://golang.org/pkg/text/template/
|
||||||
|
[sprig]: https://masterminds.github.io/sprig/
|
||||||
|
|
|
@ -18,7 +18,20 @@ func (e *envvar) enabled() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *envvar) string() string {
|
func (e *envvar) string() string {
|
||||||
return e.Value
|
segmentTemplate := e.props.getString(SegmentTemplate, "")
|
||||||
|
if len(segmentTemplate) == 0 {
|
||||||
|
return e.Value
|
||||||
|
}
|
||||||
|
template := &textTemplate{
|
||||||
|
Template: segmentTemplate,
|
||||||
|
Context: e,
|
||||||
|
Env: e.env,
|
||||||
|
}
|
||||||
|
text, err := template.render()
|
||||||
|
if err != nil {
|
||||||
|
return err.Error()
|
||||||
|
}
|
||||||
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *envvar) init(props *properties, env environmentInfo) {
|
func (e *envvar) init(props *properties, env environmentInfo) {
|
||||||
|
|
Loading…
Reference in a new issue