Created
November 14, 2017 12:30
-
-
Save DmitriyLyalyuev/4a00e5a2eb5e3e35d3238218a72e267a to your computer and use it in GitHub Desktop.
Alias for terraform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias tf='terraform' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_terraform() { | |
local cur prev words cword opts | |
_get_comp_words_by_ref -n : cur prev words cword | |
COMPREPLY=() | |
opts="" | |
if [[ ${cur} == -* ]] ; then | |
compopt -o nospace | |
fi | |
if [[ ${cword} -eq 1 ]] ; then | |
if [[ ${cur} == -* ]] ; then | |
opts="--help --version" | |
else | |
opts="$(terraform --help | grep -vE '(usage|Available|^$)' | awk '{print $1}')" | |
fi | |
fi | |
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 | |
} | |
complete -F _terraform terraform | |
complete -F _terraform tf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment