Skip to content

Commit d807510

Browse files
Enable shell completion (roboll#1559)
* feat: enable EnableBashCompletion to get --generate-bash-completion command line flag * feat: add scripts for bash and zsh * feat: document shell completion
1 parent 4e48521 commit d807510

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,10 @@ Those features are set using the environment variable `HELMFILE_EXPERIMENTAL`. H
11921192

11931193
If you want to enable all experimental features set the env var to `HELMFILE_EXPERIMENTAL=true`
11941194

1195+
## `bash` and `zsh` completion
1196+
1197+
Copy `autocomplete/helmfile_bash_autocomplete` or `autocomplete/helmfile_zsh_autocomplete` (depending on your shell of choice) to directory where you keep other shell completion scripts to make sure it is sourced.
1198+
11951199
## Examples
11961200

11971201
For more examples, see the [examples/README.md](https://github.com/roboll/helmfile/blob/master/examples/README.md) or the [`helmfile`](https://github.com/cloudposse/helmfiles/tree/master/releases) distribution by [Cloud Posse](https://github.com/cloudposse/).
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#! /bin/bash
2+
3+
_helmfile_bash_autocomplete() {
4+
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
5+
local cur opts base
6+
COMPREPLY=()
7+
cur="${COMP_WORDS[COMP_CWORD]}"
8+
if [[ "$cur" == "-"* ]]; then
9+
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )
10+
else
11+
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
12+
fi
13+
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
14+
return 0
15+
fi
16+
}
17+
18+
complete -o bashdefault -o default -o nospace -F _helmfile_bash_autocomplete helmfile
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#compdef helmfile
2+
3+
_helmfile_zsh_autocomplete() {
4+
5+
local -a opts
6+
local cur
7+
cur=${words[-1]}
8+
if [[ "$cur" == "-"* ]]; then
9+
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
10+
else
11+
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")
12+
fi
13+
14+
if [[ "${opts[1]}" != "" ]]; then
15+
_describe 'values' opts
16+
else
17+
_files
18+
fi
19+
20+
return
21+
}
22+
23+
compdef _helmfile_zsh_autocomplete helmfile

main.go

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func main() {
4242
cliApp.Name = "helmfile"
4343
cliApp.Usage = ""
4444
cliApp.Version = version.Version
45+
cliApp.EnableBashCompletion = true
4546
cliApp.Flags = []cli.Flag{
4647
cli.StringFlag{
4748
Name: "helm-binary, b",

0 commit comments

Comments
 (0)