Fix completing multiple hosts (Debian: #535585)

Fixed `_known_hosts_real' to allow for multiple patterns in ssh config, e.g.:

    Host foo.example.net bar.example.net

IFS was set to just newline (\n), whereas `compgen -W' relies on IFS
being space-tab-newline ( \t\n) to expand hostnames which are separated
by whitespace.
Tests are updated as well (added host `jar' to config).  To run the tests:

    ./runUnit _known_hosts_real.exp
This commit is contained in:
Freddy Vulto 2009-07-07 23:02:27 +02:00
parent 0c44194be2
commit 3fe193f81a
3 changed files with 5 additions and 4 deletions

View File

@ -1069,7 +1069,6 @@ _known_hosts_real()
local configfile flag prefix
local cur curd awkcur user suffix aliases global_kh user_kh hosts i host
local -a kh khd config
local IFS=$'\n'
local OPTIND=1
while getopts "acF:p:" flag "$@"; do
@ -1102,6 +1101,7 @@ _known_hosts_real()
fi
if [ ${#config[@]} -gt 0 ]; then
local OIFS=$IFS IFS=$'\n'
# expand path (if present) to global known hosts file
global_kh=($( sed -ne 's/^[ \t]*[Gg][Ll][Oo][Bb][Aa][Ll][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/\1/p' "${config[@]}" ))
for (( i=0; i < ${#global_kh[@]}; i++ )); do
@ -1112,6 +1112,7 @@ _known_hosts_real()
for (( i=0; i < ${#user_kh[@]}; i++ )); do
user_kh[i]=$(echo "${user_kh[i]//\"/}")
done
IFS=$OIFS
fi
# Global known_hosts files

View File

@ -1,6 +1,6 @@
UserKnownHostsFile fixtures/_known_hosts_real/known_hosts
# Unindented
Host gee
Host gee jar
# Indented
Host hus # With comment

View File

@ -13,9 +13,9 @@ setup
set test "Hosts should be put in COMPREPLY"
set hosts [get_hosts]
# Hosts `gee' and `hus' are defined in ./fixtures/_known_hosts_real/config
# Hosts `gee', `hus' and `jar' are defined in ./fixtures/_known_hosts_real/config
# Hosts `doo' and `ike' are defined in ./fixtures/_known_hosts_real/known_hosts
lappend hosts doo gee hus ike
lappend hosts doo gee hus ike jar
set hosts [lsort -ascii $hosts]
set hosts [join $hosts "\\s+"]
# Call _known_hosts