2022-01-26 06:54:36 -08:00
|
|
|
package segments
|
2020-09-15 04:44:53 -07:00
|
|
|
|
2022-01-26 01:23:18 -08:00
|
|
|
import (
|
|
|
|
"oh-my-posh/environment"
|
2022-01-26 04:53:35 -08:00
|
|
|
"oh-my-posh/properties"
|
2022-01-26 01:23:18 -08:00
|
|
|
"strings"
|
|
|
|
)
|
2021-09-17 12:48:00 -07:00
|
|
|
|
2022-01-26 05:10:18 -08:00
|
|
|
type Shell struct {
|
2022-01-26 04:53:35 -08:00
|
|
|
props properties.Properties
|
2022-01-26 01:23:18 -08:00
|
|
|
env environment.Environment
|
2022-01-22 10:46:56 -08:00
|
|
|
|
2022-04-20 10:16:02 -07:00
|
|
|
Name string
|
|
|
|
Version 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
|
2022-01-26 04:53:35 -08:00
|
|
|
MappedShellNames properties.Property = "mapped_shell_names"
|
2021-09-17 12:48:00 -07:00
|
|
|
)
|
|
|
|
|
2022-01-26 05:26:56 -08:00
|
|
|
func (s *Shell) Template() string {
|
2022-02-01 05:07:58 -08:00
|
|
|
return " {{ .Name }} "
|
2022-01-23 12:37:51 -08:00
|
|
|
}
|
|
|
|
|
2022-01-26 05:26:56 -08:00
|
|
|
func (s *Shell) Enabled() bool {
|
2022-01-26 04:09:21 -08:00
|
|
|
mappedNames := s.props.GetKeyValueMap(MappedShellNames, make(map[string]string))
|
2022-01-23 12:37:51 -08:00
|
|
|
s.Name = s.env.Shell()
|
2022-04-20 10:16:02 -07:00
|
|
|
s.Version = s.env.Flags().ShellVersion
|
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
|
|
|
|
}
|
|
|
|
|
2022-01-26 05:26:56 -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
|
|
|
|
}
|