Isso faz o truque:
#compdef anssh
local -a command
_anssh () {
command="$words"
_arguments '-i[inventory file]:filename:->files'
case "$state" in
files)
_anssh_inventories_show
;;
*)
_anssh_hosts_show
;;
esac
}
_anssh_inventories_show () {
local -a inventories
inventories=("${(@f)$(find hosts -maxdepth 1 -type f -printf 'hosts/%f\n')}")
_multi_parts / inventories
}
_anssh_hosts_show () {
local inv=$(echo $command | grep ' -i' | sed 's/.*\-i\s*//g' | awk '{print $1}')
local invflag=""
if [ "$inv" != "" ]; then
invflag="-i $inv"
fi
local hosts=("${(s/ /)$(anssh $invflag -l)}")
_values 'hosts' $hosts
}
_anssh