mirror of
https://github.com/octoleo/hosts.git
synced 2024-11-25 14:17:48 +00:00
Add autocomplete functions for bash and zsh.
This commit is contained in:
parent
e9f3dc5431
commit
370e1f6688
22
hosts.autocomplete.bash
Normal file
22
hosts.autocomplete.bash
Normal 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
24
hosts.autocomplete.zsh
Normal 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
|
Loading…
Reference in New Issue
Block a user