From 370e1f66880884aa6f591fd64010d61e9712c5c9 Mon Sep 17 00:00:00 2001 From: William Melody Date: Wed, 1 Mar 2017 12:30:25 -0800 Subject: [PATCH] Add autocomplete functions for bash and zsh. --- hosts.autocomplete.bash | 22 ++++++++++++++++++++++ hosts.autocomplete.zsh | 24 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 hosts.autocomplete.bash create mode 100644 hosts.autocomplete.zsh 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