[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 3fe193f81a3e708d3f235e670ba0c1a9050a1a18

Freddy Vulto (none) freddy at rebase.
Tue Jul 7 22:02:09 UTC 2009


The following commit has been merged in the master branch:
commit 3fe193f81a3e708d3f235e670ba0c1a9050a1a18
Author: Freddy Vulto <freddy at rebase.(none)>
Date:   Tue Jul 7 23:02:27 2009 +0200

    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

diff --git a/bash_completion b/bash_completion
index e38dca7..8351014 100644
--- a/bash_completion
+++ b/bash_completion
@@ -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
diff --git a/test/fixtures/_known_hosts_real/config b/test/fixtures/_known_hosts_real/config
index 9b9da43..77770ff 100644
--- a/test/fixtures/_known_hosts_real/config
+++ b/test/fixtures/_known_hosts_real/config
@@ -1,6 +1,6 @@
     UserKnownHostsFile fixtures/_known_hosts_real/known_hosts
 
     # Unindented
-Host gee
+Host gee jar
 	# Indented
     Host hus  # With comment
diff --git a/test/unit/_known_hosts_real.exp b/test/unit/_known_hosts_real.exp
index 9acd7b6..a698b92 100644
--- a/test/unit/_known_hosts_real.exp
+++ b/test/unit/_known_hosts_real.exp
@@ -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

-- 
bash-completion



More information about the Bash-completion-commits mailing list