split _known_hosts into _kwnown_hosts and _known_hosts_real, instead of using an option to set current word

This commit is contained in:
Guillaume Rousse 2009-05-03 15:18:31 +02:00
parent ae757e453b
commit d5fd1c3412
3 changed files with 19 additions and 16 deletions

View File

@ -2703,29 +2703,32 @@ shopt -u hostcomplete && complete -F _user_at_host $nospace talk ytalk finger
# -F configfile Use `configfile' for configuration settings # -F configfile Use `configfile' for configuration settings
# -h host Complete on given host # -h host Complete on given host
_known_hosts() _known_hosts()
{
local cur
COMPREPLY=()
cur=`_get_cword`
_known_hosts_real $@
}
_known_hosts_real()
{ {
local configfile local configfile
local cur curd ocur user suffix aliases global_kh user_kh hosts i host local curd ocur user suffix aliases global_kh user_kh hosts i host
local -a kh khd config local -a kh khd config
local IFS=$'\n' local IFS=$'\n'
local OPTIND=1 local OPTIND=1
local cur_set=0 while getopts "acF:" flag "$@"; do
while getopts "acF:h:" flag "$@"; do
case $flag in case $flag in
a) aliases='yes' ;; a) aliases='yes' ;;
c) suffix=':' ;; c) suffix=':' ;;
F) configfile="$OPTARG" ;; F) configfile="$OPTARG" ;;
h) cur="$OPTARG"; cur_set=1 ;;
esac esac
done done
COMPREPLY=()
if [ $cur_set = 0 ]; then
cur=`_get_cword`
fi
ocur=$cur ocur=$cur
[[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@} [[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@}
kh=() kh=()

View File

@ -95,7 +95,7 @@ _ssh()
fi fi
shift shift
done done
_known_hosts -a "$optconfigfile" _known_hosts_real -a "$optconfigfile"
else else
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -c -- $cur ) ) COMPREPLY=( "${COMPREPLY[@]}" $( compgen -c -- $cur ) )
fi fi
@ -145,7 +145,7 @@ _sftp()
fi fi
shift shift
done done
_known_hosts -a "$optconfigfile" _known_hosts_real -a "$optconfigfile"
fi fi
return 0 return 0
@ -201,7 +201,7 @@ _scp()
shift shift
done done
[[ "$cur" == */* ]] || _known_hosts -c -a "$optconfigfile" [[ "$cur" == */* ]] || _known_hosts_real -c -a "$optconfigfile"
# This approach is used instead of _filedir to get a space appended # This approach is used instead of _filedir to get a space appended
# after local file/dir completions, and $nospace retained for others. # after local file/dir completions, and $nospace retained for others.
@ -234,7 +234,7 @@ _ssh_copy_id() {
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-i' -- $cur ) ) COMPREPLY=( $( compgen -W '-i' -- $cur ) )
else else
_known_hosts -a _known_hosts_real -a
fi fi
return 0 return 0

View File

@ -12,20 +12,20 @@ _xhost ()
case "$cur" in case "$cur" in
+*) +*)
cur=${cur:1} cur=${cur:1}
_known_hosts -h "$cur" _known_hosts_real
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
COMPREPLY[i]=+${COMPREPLY[i]} COMPREPLY[i]=+${COMPREPLY[i]}
done done
;; ;;
-*) -*)
cur=${cur:1} cur=${cur:1}
_known_hosts -h "$cur" _known_hosts_real
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
COMPREPLY[i]=-${COMPREPLY[i]} COMPREPLY[i]=-${COMPREPLY[i]}
done done
;; ;;
*) *)
_known_hosts -h "$cur" _known_hosts_real
;; ;;
esac esac