Skip to content

Instantly share code, notes, and snippets.

@glidenote
Created April 14, 2012 00:45
Show Gist options
  • Save glidenote/2381208 to your computer and use it in GitHub Desktop.
Save glidenote/2381208 to your computer and use it in GitHub Desktop.
.zshrc for mosh
# mosh
function _mosh_hosts {
local -a config_hosts
local config
integer ind
# If users-hosts matches, we shouldn't complete anything else.
if [[ "$IPREFIX" == *@ ]]; then
_combination -s '[:@]' my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@" && return
else
_combination -s '[:@]' my-accounts users-hosts \
${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@" && return
fi
if (( ind = ${words[(I)-F]} )); then
config=${~words[ind+1]}
else
config="$HOME/.ssh/config"
fi
if [[ -r $config ]]; then
local IFS=$'\t ' key hosts host
while read key hosts; do
if [[ "$key" == (#i)host ]]; then
for host in ${(z)hosts}; do
case $host in
(*[*?]*) ;;
(*) config_hosts+=("$host") ;;
esac
done
fi
done < "$config"
if (( ${#config_hosts} )); then
_wanted hosts expl 'remote host name' \
compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" $config_hosts
fi
fi
}
compdef _mosh_hosts mosh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment