oh-my-posh/src/segment_shell.go

41 lines
761 B
Go
Raw Normal View History

2020-09-15 04:44:53 -07:00
package main
import (
"oh-my-posh/environment"
"oh-my-posh/properties"
"strings"
)
2022-01-26 05:10:18 -08:00
type Shell struct {
props properties.Properties
env environment.Environment
2022-01-22 10:46:56 -08:00
Name string
2020-09-15 04:44:53 -07:00
}
const (
// MappedShellNames allows for custom text in place of shell names
MappedShellNames properties.Property = "mapped_shell_names"
)
2022-01-26 05:10:18 -08:00
func (s *Shell) template() string {
return "{{ .Name }}"
}
2022-01-26 05:10:18 -08:00
func (s *Shell) enabled() bool {
2022-01-26 04:09:21 -08:00
mappedNames := s.props.GetKeyValueMap(MappedShellNames, make(map[string]string))
s.Name = s.env.Shell()
for key, val := range mappedNames {
2022-01-22 10:46:56 -08:00
if strings.EqualFold(s.Name, key) {
s.Name = val
break
}
}
2022-01-22 10:46:56 -08:00
return true
}
2022-01-26 05:10:18 -08:00
func (s *Shell) init(props properties.Properties, env environment.Environment) {
2020-09-15 04:44:53 -07:00
s.props = props
s.env = env
}