rendered paste body# ssh(1) completion
#
have ssh && {
_ssh()
{
local cur prev
local -a config
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
case "$prev" in
-*c)
COMPREPLY=( $( compgen -W 'blowfish 3des 3des-cbc blowfish-cbc \
arcfour cast128-cbc' -- $cur ) )
;;
-*i)
_filedir
;;
-*l)
COMPREPLY=( $( compgen -u -- $cur ) )
;;
*)
_known_hosts -a
[ $COMP_CWORD -eq 1 ] || \
COMPREPLY=( ${COMPREPLY[@]} $( compgen -c -- $cur ) )
esac
return 0
}
shopt -u hostcomplete && complete -F _ssh ssh slogin sftp xhost autossh
# scp(1) completion
#
_scp()
{
local cur userhost path
local IFS=$'\t\n'
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
_expand || return 0
if [[ "$cur" == *:* ]]; then
# remove backslash escape from :
cur=${cur/\\:/:}
userhost=${cur%%?(\\):*}
path=${cur#*:}
# unescape spaces
path=${path//\\\\\\\\ / }
if [ -z "$path" ]; then
# default to home dir of specified user on remote host
path=$(ssh -o 'Batchmode yes' $userhost pwd 2>/dev/null)
fi
# escape spaces; remove executables, aliases, pipes and sockets;
# add space at end of file names
COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \
command ls -aF1d "$path*" 2>/dev/null | \
sed -e 's/ /\\\\\\\ /g' -e 's/[*@|=]$//g' \
-e 's/[^\/]$/& /g' ) )
return 0
fi
[[ "$cur" == */* ]] || _known_hosts -c -a
COMPREPLY=( ${COMPREPLY[@]} $( command ls -aF1d $cur* \
2>/dev/null | sed -e 's/ /\\ /g' -e 's/[*@|=]$//g'\
-e 's/[^\/]$/& /g' ) )
return 0
}