diff --git a/src/shell/if_test.go b/src/shell/if_test.go index a1afe78..970a033 100644 --- a/src/shell/if_test.go +++ b/src/shell/if_test.go @@ -32,6 +32,16 @@ func TestIf(t *testing.T) { If: `eq .Shell "pwsh"`, Expected: true, }, + { + Case: "Only two shells", + If: `match .Shell "bash" "zsh"`, + Expected: false, + }, + { + Case: "Only two shells", + If: `match .Shell "pwsh" "nu"`, + Expected: true, + }, } for _, tc := range cases { diff --git a/src/shell/template.go b/src/shell/template.go index 057f2c0..e4aa5c6 100644 --- a/src/shell/template.go +++ b/src/shell/template.go @@ -48,6 +48,7 @@ func funcMap() template.FuncMap { "formatString": formatString, "cleanString": cleanString, "env": os.Getenv, + "match": match, } return template.FuncMap(funcMap) } @@ -76,3 +77,12 @@ func cleanString(variable interface{}) interface{} { return variable } } + +func match(variable string, values ...string) bool { + for _, value := range values { + if variable == value { + return true + } + } + return false +} diff --git a/website/docs/setup/templates.mdx b/website/docs/setup/templates.mdx index 12e1457..5a0c0f5 100644 --- a/website/docs/setup/templates.mdx +++ b/website/docs/setup/templates.mdx @@ -19,11 +19,12 @@ configuration across multiple environments resulting in environment specific val Out of the box you get the following functionality: -| Name | Type | Description | Example | -| -------- | ---------- | ----------------------------------------------------------- | ------------------------------------------------------------------ | -| `.Shell` | `string` | the current shell name | `{{ .Shell }}` | -| `.Home` | `string` | the user's `$HOME` folder | `{{ .Home }}/go/bin/aliae` | -| `.OS` | `string` | the current operating system (`windows`, `darwin`, `linux`) | `{{ .Home }}/go/bin/aliae{{ if eq .OS \"windows\" }}.exe{{ end }}` | -| `env` | `function` | retrieve an environment variable value | `{{ env \"POSH_THEME\" }}` | +| Name | Type | Description | Example | +| -------- | ---------- | ----------------------------------------------------------- | ---------------------------------------------------------------- | +| `.Shell` | `string` | the current shell name | `{{ .Shell }}` | +| `.Home` | `string` | the user's `$HOME` folder | `{{ .Home }}/go/bin/aliae` | +| `.OS` | `string` | the current operating system (`windows`, `darwin`, `linux`) | `{{ .Home }}/go/bin/aliae{{ if eq .OS "windows" }}.exe{{ end }}` | +| `env` | `function` | retrieve an environment variable value | `{{ env "POSH_THEME" }}` | +| `match` | `function` | match a shell name to one or multiple options | `{{ match .Shell "zsh" "bash" }}` | [go-text-template]: https://golang.org/pkg/text/template/