diff --git a/docs/docs/segment-shell.md b/docs/docs/segment-shell.md index d1d4dd3d..5ae1697b 100644 --- a/docs/docs/segment-shell.md +++ b/docs/docs/segment-shell.md @@ -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) diff --git a/src/segment_shell.go b/src/segment_shell.go index c3fcc057..782433ed 100644 --- a/src/segment_shell.go +++ b/src/segment_shell.go @@ -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) { diff --git a/src/segment_shell_test.go b/src/segment_shell_test.go index f808c692..278414cc 100644 --- a/src/segment_shell_test.go +++ b/src/segment_shell_test.go @@ -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) + } +} diff --git a/themes/schema.json b/themes/schema.json index 76d5bbd1..53dae094 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -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": {} + } + } + } + } } }, {