2020-09-15 04:44:53 -07:00
|
|
|
package main
|
|
|
|
|
2021-09-17 12:48:00 -07:00
|
|
|
import "strings"
|
|
|
|
|
2020-09-15 04:44:53 -07:00
|
|
|
type shell struct {
|
2022-01-01 11:08:08 -08:00
|
|
|
props Properties
|
2022-01-01 11:09:52 -08:00
|
|
|
env Environment
|
2022-01-22 10:46:56 -08:00
|
|
|
|
|
|
|
Name string
|
2020-09-15 04:44:53 -07:00
|
|
|
}
|
|
|
|
|
2021-09-17 12:48:00 -07:00
|
|
|
const (
|
|
|
|
// MappedShellNames allows for custom text in place of shell names
|
|
|
|
MappedShellNames Property = "mapped_shell_names"
|
|
|
|
)
|
|
|
|
|
2020-09-15 04:44:53 -07:00
|
|
|
func (s *shell) enabled() bool {
|
2021-09-17 12:48:00 -07:00
|
|
|
mappedNames := s.props.getKeyValueMap(MappedShellNames, make(map[string]string))
|
2022-01-22 10:46:56 -08:00
|
|
|
s.Name = s.env.getShellName()
|
2021-09-17 12:48:00 -07:00
|
|
|
for key, val := range mappedNames {
|
2022-01-22 10:46:56 -08:00
|
|
|
if strings.EqualFold(s.Name, key) {
|
|
|
|
s.Name = val
|
2021-09-17 12:48:00 -07:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2022-01-22 10:46:56 -08:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *shell) string() string {
|
|
|
|
segmentTemplate := s.props.getString(SegmentTemplate, "{{.Name}}")
|
|
|
|
template := &textTemplate{
|
|
|
|
Template: segmentTemplate,
|
|
|
|
Context: s,
|
|
|
|
Env: s.env,
|
|
|
|
}
|
|
|
|
text, err := template.render()
|
|
|
|
if err != nil {
|
|
|
|
return err.Error()
|
|
|
|
}
|
|
|
|
return text
|
2020-09-15 04:44:53 -07:00
|
|
|
}
|
|
|
|
|
2022-01-01 11:09:52 -08:00
|
|
|
func (s *shell) init(props Properties, env Environment) {
|
2020-09-15 04:44:53 -07:00
|
|
|
s.props = props
|
|
|
|
s.env = env
|
|
|
|
}
|