1
0
mirror of https://github.com/octoleo/hosts.git synced 2024-11-22 04:45:11 +00:00

Add autocomplete functions for bash and zsh.

This commit is contained in:
William Melody 2017-03-01 12:30:25 -08:00
parent e9f3dc5431
commit 370e1f6688
2 changed files with 46 additions and 0 deletions

22
hosts.autocomplete.bash Normal file
View File

@ -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

24
hosts.autocomplete.zsh Normal file
View File

@ -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