Commit 90f8b0c7 authored by Robert Spencer's avatar Robert Spencer
Browse files

Add awit-ssh host name completion

parent 2bc704f4
# compsys initialization
autoload -U compinit
# Get an array of known SSH host names after deleting:
# - Everything after the first column of host names or IPs
# - Square brackets and attached port numbers
# - IP addresses
# - Encrypted host names
hosts=( `sed -e 's/[, ].*//g' -e 's/\[\([^]]*\)\].*/\1/' -e '/^[0-9]\+/d' -e '/^|1|/d' $HOME/.ssh/known_hosts` )
zstyle ':completion:*:hosts' hosts $hosts
die() {
echo "$1"
exit 1
grep -q '^|1|' ~/.ssh/known_hosts && die "ERROR: ~/.ssh/known_hosts is hashed. Aborting!
Please see this contributions for more information."
if [ ! -e ~/.zsh/completion/_awit-ssh ]; then
# Install
ln -s ~/.zsh/contrib/awit-ssh-completion/_awit-ssh ~/.zsh/completion/
echo "Installed ~/.zsh/completion/_awit-ssh"
# Uninstall
rm -f ~/.zsh/completion/_awit-ssh
echo "Uninstalled ~/.zsh/completion/_awit-ssh"
if [ ! -e ~/.zsh/zshrc.d/51-completion-awit-ssh.zsh ]; then
# Install
ln -s ~/.zsh/contrib/awit-ssh-completion/51-completion-awit-ssh.zsh ~/.zsh/zshrc.d/
echo "Installed ~/.zsh/zshrc.d/51-completion-awit-ssh.zsh"
# Uninstall
rm -f ~/.zsh/zshrc.d/51-completion-awit-ssh.zsh
echo "Uninstalled ~/.zsh/zshrc.d/51-completion-awit-ssh.zsh"
# awit-ssh Completion
If you want to use awit-ssh completion with zsh you first need to clean up your ~/.ssh/known_hosts file if it is hashed.
Run the follow and if you see any number other than zero, your ~/.ssh/known_hosts file is hashed
grep -c '^|1|' ~/.ssh/known_hosts
Since you need the file unencrypted make a backup of ~/.ssh/known_hosts and then add the following lines to the top of ~/.ssh/config
Host *
HashKnownHosts no
Then delete the hashed lines
sed -i '/^|1|/d' ~/.ssh/known_hosts
Going forward host names will be added in plain text. You'll be prompted to re-add the deleted hosts names as you log in to each server again.
#compdef awit-ssh
local curcontext="$curcontext" state line expl ret=1
local -a _comp_priv_prefix
_arguments -C \
'(-?)--help[display help information]' \
'--version[display version information]' \
'--forward-agent[forward the ssh-agent socket]' \
'--knock[knock on HOST:PORT to gain access]' \
'--rsync[use rsync to rsync data from remote server to DEST]' \
'--libvirt-vnc[connect to remote VNC server HOST:PORT]' \
'1:remote host name:->userhost' \
'*:::args:_normal' && ret=0
case $state in
if compset -P '*@'; then
_wanted hosts expl 'remote host name' _ssh_hosts && ret=0
elif compset -S '@*'; then
_wanted users expl 'login name' _combination -s '[:@]' my-accounts users-hosts users -S '' && ret=0
_alternative \
'hosts:remote host name:_ssh_hosts' \
'users:login name:_combination -s "[:@]" my-accounts users-hosts users -qS@' && ret=0
return ret
......@@ -31,3 +31,6 @@ zstyle ':completion:*' verbose true
#zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
#zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
# Add custom completion scripts
fpath=(~/.zsh/completion $fpath)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment