diff --git a/hosts.autocomplete.bash b/hosts.autocomplete.bash new file mode 100644 index 0000000..f832cc8 --- /dev/null +++ b/hosts.autocomplete.bash @@ -0,0 +1,22 @@ +__hosts_subcommands() { + local _commands + _commands=($(hosts commands --raw)) + local _completions + _completions=(${_commands[@]}) + + local _current="${COMP_WORDS[COMP_CWORD]}" + COMPREPLY=() + + + for __command in "${_commands[@]}" + do + if [[ -n "${__command}" ]] + then + _completions+=("${__command}") + fi + done + + COMPREPLY=($(compgen -W "${_completions[*]}" -- "${_current}")) +} + +complete -F __hosts_subcommands hosts diff --git a/hosts.autocomplete.zsh b/hosts.autocomplete.zsh new file mode 100644 index 0000000..ca26af2 --- /dev/null +++ b/hosts.autocomplete.zsh @@ -0,0 +1,24 @@ +__hosts_subcommands() { + local _commands + _commands=($(hosts commands --raw)) + local _completions + _completions=(${_commands[@]}) + + for __command in "${_commands[@]}" + do + if [[ -n "${__command}" ]] + then + _completions+=("${__command}") + fi + done + + if [[ "${?}" -eq 0 ]] + then + compadd -- "${_completions[@]}" + return 0 + else + return 1 + fi +} + +compdef __hosts_subcommands hosts