141 lines
2.8 KiB
Plaintext
Raw Normal View History

# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
# ex: ts=8 sw=8 noet filetype=sh
#
2008-09-27 12:58:42 +02:00
# ssh(1) completion
#
have ssh && {
_ssh()
{
local cur prev
local optconfigfile
2008-09-27 12:58:42 +02:00
local -a config
COMPREPLY=()
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
case "$prev" in
-F)
_filedir
;;
2008-09-27 12:58:42 +02:00
-*c)
COMPREPLY=( $( compgen -W 'blowfish 3des 3des-cbc blowfish-cbc \
arcfour cast128-cbc' -- $cur ) )
;;
-*i)
_filedir
;;
-*l)
COMPREPLY=( $( compgen -u -- $cur ) )
;;
*)
# Search COMP_WORDS for '-F configfile' argument
set -- "${COMP_WORDS[@]}"
while [ $# -gt 0 ]; do
if [ "${1:0:2}" = -F ]; then
if [ ${#1} -gt 2 ]; then
2008-11-08 09:45:31 +01:00
optconfigfile="$(dequote "$1")"
else
shift
2008-11-08 09:45:31 +01:00
[ "$1" ] && optconfigfile="$(dequote "-F$1")"
fi
break
fi
shift
done
2008-11-08 09:45:31 +01:00
_known_hosts -a "$optconfigfile"
2008-09-27 12:58:42 +02:00
[ $COMP_CWORD -eq 1 -o -n "$optconfigfile" ] || \
2008-09-27 12:58:42 +02:00
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 optconfigfile
2008-09-27 12:58:42 +02:00
COMPREPLY=()
cur=`_get_cword ":"`
_expand || return 0
if [[ "$cur" == *:* ]]; then
local IFS=$'\t\n'
# 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" \
2008-09-27 12:58:42 +02:00
-e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
return 0
fi
# Search COMP_WORDS for '-F configfile' argument
set -- "${COMP_WORDS[@]}"
while [ $# -gt 0 ]; do
if [ "${1:0:2}" = -F ]; then
if [ ${#1} -gt 2 ]; then
2008-11-08 09:45:31 +01:00
optconfigfile="$(dequote "$1")"
else
shift
2008-11-08 09:45:31 +01:00
[ "$1" ] && optconfigfile="$(dequote "-F$1")"
fi
break
fi
shift
done
2008-09-27 12:58:42 +02:00
2008-11-08 09:45:31 +01:00
[[ "$cur" == */* ]] || _known_hosts -c -a "$optconfigfile"
local IFS=$'\t\n'
COMPREPLY=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* \
2>/dev/null | sed \
-e "s/[][(){}<>\",:;^&\!$=?\`|\\ ']/\\\\&/g" \
-e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
2008-09-27 12:58:42 +02:00
return 0
}
complete -F _scp $nospace scp
# ssh-copy-id(1) completion
#
2008-10-24 19:19:37 +02:00
_ssh_copy_id() {
2008-09-27 12:58:42 +02:00
local cur prev
COMPREPLY=()
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
case "$prev" in
-*i)
_filedir
;;
*)
_known_hosts -a
[ $COMP_CWORD -eq 1 ] || \
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -- $cur ) )
esac
return 0
}
2008-10-24 19:19:37 +02:00
complete -F _ssh_copy_id $filenames ssh-copy-id
}