Update Terraform Completion

pull/1136/head
LanikSJ 2018-01-21 11:07:48 -08:00
parent a9b606eaab
commit 2930506687
No known key found for this signature in database
GPG Key ID: C043F668DB04FD0E
1 changed files with 29 additions and 20 deletions

View File

@ -1,26 +1,35 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Bash Terraform completion # Bash Terraform completion
# Source: https://gist.github.com/cornfeedhobo/8bc08747ec3add1fc5adb2edb7cd68d3
_terraform() _terraform() {
{ local cur prev words cword opts
local cmds cur colonprefixes _get_comp_words_by_ref -n : cur prev words cword
cmds="apply destroy fmt get graph import init \ COMPREPLY=()
output plan push refresh remote show taint \ opts=""
untaint validate version state"
COMPREPLY=() if [[ ${cur} == -* ]] ; then
cur=${COMP_WORDS[COMP_CWORD]} compopt -o nospace
# Work-around bash_completion issue where bash interprets a colon fi
# as a separator.
# Work-around borrowed from the darcs work-around for the same if [[ ${cword} -eq 1 ]] ; then
# issue. if [[ ${cur} == -* ]] ; then
colonprefixes=${cur%"${cur##*:}"} opts="--help --version"
COMPREPLY=( $(compgen -W '$cmds' -- $cur)) else
local i=${#COMPREPLY[*]} opts="$(terraform --help | grep -vE '(usage|Available|^$)' | awk '{print $1}')"
while [ $((--i)) -ge 0 ]; do fi
COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"} fi
done
if [[ ${cword} -gt 1 ]] ; then
if [[ ${cword} -eq 2 && ${prev} == '--help' ]] ; then
opts="$(terraform --help | grep -vE '(usage|Available|^$)' | awk '{print $1}')"
else
opts="$(terraform --help "${words[1]}" | grep '^ *-[a-z]' | awk '{print $1}' | awk -F '=' '{if ($0 ~ /=/) {print $1"="} else {print $1" "}}')"
fi
fi
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
return 0
} &&
complete -F _terraform terraform complete -F _terraform terraform