feat: allow for custom text in place of shell names

This commit is contained in:
Aaron Sherber 2021-09-17 15:48:00 -04:00 committed by GitHub
parent bf51f59ceb
commit f412ef6644
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 3 deletions

View file

@ -18,7 +18,13 @@ Show the current shell name (ZSH, powershell, bash, ...).
"foreground": "#ffffff",
"background": "#0077c2",
"properties": {
"prefix": " \uFCB5 "
"mapped_shell_names": {
"pwsh": "PS"
}
}
}
```
## Properties
- mapped_shell_names: `object` - custom glyph/text to use in place of specified shell names (case-insensitive)

View file

@ -1,16 +1,31 @@
package main
import "strings"
type shell struct {
props *properties
env environmentInfo
}
const (
// MappedShellNames allows for custom text in place of shell names
MappedShellNames Property = "mapped_shell_names"
)
func (s *shell) enabled() bool {
return true
}
func (s *shell) string() string {
return s.env.getShellName()
mappedNames := s.props.getKeyValueMap(MappedShellNames, make(map[string]string))
shellName := s.env.getShellName()
for key, val := range mappedNames {
if strings.EqualFold(shellName, key) {
shellName = val
break
}
}
return shellName
}
func (s *shell) init(props *properties, env environmentInfo) {

View file

@ -17,3 +17,28 @@ func TestWriteCurrentShell(t *testing.T) {
}
assert.Equal(t, expected, s.string())
}
func TestUseMappedShellNames(t *testing.T) {
cases := []struct {
Shell string
Expected string
}{
{Shell: "zsh", Expected: "zsh"},
{Shell: "pwsh", Expected: "PS"},
{Shell: "PWSH", Expected: "PS"},
}
for _, tc := range cases {
env := new(MockedEnvironment)
env.On("getShellName", nil).Return(tc.Expected, nil)
s := &shell{
env: env,
props: &properties{
values: map[Property]interface{}{
MappedShellNames: map[string]string{"pwsh": "PS"},
},
},
}
got := s.string()
assert.Equal(t, tc.Expected, got)
}
}

View file

@ -1402,7 +1402,19 @@
},
"then": {
"title": "Shell Segment",
"description": "https://ohmyposh.dev/docs/shell"
"description": "https://ohmyposh.dev/docs/shell",
"properties": {
"properties": {
"properties": {
"custom_text": {
"type": "object",
"title": "Custom Text",
"description": "Custom glyph/text for specific shells",
"default": {}
}
}
}
}
}
},
{