_known_hosts(): finally thought of a way to correctly perform completion
when host specification is of the form user@host _known_hosts(): moved escaping of dots in $cur to within 'if' block that requires it
This commit is contained in:
parent
f433992548
commit
406c771277
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# <![CDATA[
|
# <![CDATA[
|
||||||
#
|
#
|
||||||
# $Id: bash_completion,v 1.56 2002/01/16 03:16:56 ianmacd Exp $
|
# $Id: bash_completion,v 1.57 2002/01/16 08:14:14 ianmacd Exp $
|
||||||
#
|
#
|
||||||
# Copyright (C) Ian Macdonald <ian@caliban.org>
|
# Copyright (C) Ian Macdonald <ian@caliban.org>
|
||||||
#
|
#
|
||||||
@ -1005,14 +1005,11 @@ _chkconfig()
|
|||||||
#
|
#
|
||||||
_known_hosts()
|
_known_hosts()
|
||||||
{
|
{
|
||||||
local cur kh
|
local cur kh user
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
cur=${cur#*@}
|
[[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@}
|
||||||
# Escape slashes and dots in paths for awk
|
|
||||||
cur=${cur//\//\\\/}
|
|
||||||
cur=${cur//\./\\\.}
|
|
||||||
kh=()
|
kh=()
|
||||||
|
|
||||||
[ -r /etc/known_hosts ] && kh[0]=/etc/known_hosts
|
[ -r /etc/known_hosts ] && kh[0]=/etc/known_hosts
|
||||||
@ -1022,6 +1019,9 @@ _known_hosts()
|
|||||||
|
|
||||||
# If we have known_hosts files to use
|
# If we have known_hosts files to use
|
||||||
if [ ${#kh[@]} -gt 0 ]; then
|
if [ ${#kh[@]} -gt 0 ]; then
|
||||||
|
# Escape slashes and dots in paths for awk
|
||||||
|
cur=${cur//\//\\\/}
|
||||||
|
cur=${cur//\./\\\.}
|
||||||
if [[ "$cur" == [0-9]*.* ]]; then
|
if [[ "$cur" == [0-9]*.* ]]; then
|
||||||
# Digits followed by a dot - just search for that
|
# Digits followed by a dot - just search for that
|
||||||
cur="^$cur.*"
|
cur="^$cur.*"
|
||||||
@ -1041,6 +1041,9 @@ _known_hosts()
|
|||||||
gsub(" .*$", "", $i); \
|
gsub(" .*$", "", $i); \
|
||||||
if ($i ~ /'$cur'/) {print $i} \
|
if ($i ~ /'$cur'/) {print $i} \
|
||||||
}}' ${kh[@]} ) )
|
}}' ${kh[@]} ) )
|
||||||
|
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
|
||||||
|
COMPREPLY[i]=$user${COMPREPLY[i]}
|
||||||
|
done
|
||||||
else
|
else
|
||||||
# Just do normal hostname completion
|
# Just do normal hostname completion
|
||||||
COMPREPLY=( $( compgen -A hostname $cur ) )
|
COMPREPLY=( $( compgen -A hostname $cur ) )
|
||||||
@ -1078,7 +1081,7 @@ _ssh()
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
[ "$have" ] && complete -F _ssh ssh slogin sftp
|
[ "$have" ] && shopt -u hostcomplete && complete -F _ssh ssh slogin sftp
|
||||||
|
|
||||||
have scp &&
|
have scp &&
|
||||||
_scp()
|
_scp()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user