mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
feat: allow for custom text in place of shell names
This commit is contained in:
parent
bf51f59ceb
commit
f412ef6644
|
@ -18,7 +18,13 @@ Show the current shell name (ZSH, powershell, bash, ...).
|
||||||
"foreground": "#ffffff",
|
"foreground": "#ffffff",
|
||||||
"background": "#0077c2",
|
"background": "#0077c2",
|
||||||
"properties": {
|
"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)
|
||||||
|
|
|
@ -1,16 +1,31 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
type shell struct {
|
type shell struct {
|
||||||
props *properties
|
props *properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
// MappedShellNames allows for custom text in place of shell names
|
||||||
|
MappedShellNames Property = "mapped_shell_names"
|
||||||
|
)
|
||||||
|
|
||||||
func (s *shell) enabled() bool {
|
func (s *shell) enabled() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *shell) string() string {
|
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) {
|
func (s *shell) init(props *properties, env environmentInfo) {
|
||||||
|
|
|
@ -17,3 +17,28 @@ func TestWriteCurrentShell(t *testing.T) {
|
||||||
}
|
}
|
||||||
assert.Equal(t, expected, s.string())
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1402,7 +1402,19 @@
|
||||||
},
|
},
|
||||||
"then": {
|
"then": {
|
||||||
"title": "Shell Segment",
|
"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": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue