mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-03 15:27:26 -08:00
41 lines
721 B
Go
41 lines
721 B
Go
package main
|
|
|
|
type envvar struct {
|
|
props properties
|
|
env environmentInfo
|
|
Value string
|
|
}
|
|
|
|
const (
|
|
// VarName name of the variable
|
|
VarName Property = "var_name"
|
|
)
|
|
|
|
func (e *envvar) enabled() bool {
|
|
name := e.props.getString(VarName, "")
|
|
e.Value = e.env.getenv(name)
|
|
return e.Value != ""
|
|
}
|
|
|
|
func (e *envvar) string() string {
|
|
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) {
|
|
e.props = props
|
|
e.env = env
|
|
}
|