[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.90-84-g17c9722

Ville Skyttä ville.skytta at iki.fi
Mon Dec 5 20:00:04 UTC 2011


The following commit has been merged in the master branch:
commit 17c9722733a3e50f7b5113ca99fba9424b078274
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Mon Dec 5 21:58:04 2011 +0200

    _known_hosts_real: Support > 1 files per *KnownHostsFile line (Debian: #650514).

diff --git a/bash_completion b/bash_completion
index 03e31d4..835146f 100644
--- a/bash_completion
+++ b/bash_completion
@@ -1425,21 +1425,28 @@ _known_hosts_real()
 
     # Known hosts files from configs
     if [[ ${#config[@]} -gt 0 ]]; then
-        local OIFS=$IFS IFS=$'\n'
+        local OIFS=$IFS IFS=$'\n' j
         local -a tmpkh
         # expand paths (if present) to global and user known hosts files
         # TODO(?): try to make known hosts files with more than one consecutive
         #          spaces in their name work (watch out for ~ expansion
         #          breakage! Alioth#311595)
         tmpkh=( $( awk 'sub("^[ \t]*([Gg][Ll][Oo][Bb][Aa][Ll]|[Uu][Ss][Ee][Rr])[Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee][ \t]+", "") { print $0 }' "${config[@]}" | sort -u ) )
+        IFS=$OIFS
         for i in "${tmpkh[@]}"; do
-            # Remove possible quotes
-            i=${i//\"}
-            # Eval/expand possible `~' or `~user'
-            __expand_tilde_by_ref i
-            [[ -r $i ]] && kh+=( "$i" )
+            # First deal with quoted entries...
+            while [[ $i =~ ^([^\"]*)\"([^\"]*)\"(.*)$ ]]; do
+                i=${BASH_REMATCH[1]}${BASH_REMATCH[3]}
+                j=${BASH_REMATCH[2]}
+                __expand_tilde_by_ref j # Eval/expand possible `~' or `~user'
+                [[ -r $j ]] && kh+=( "$j" )
+            done
+            # ...and then the rest.
+            for j in $i; do
+                __expand_tilde_by_ref j # Eval/expand possible `~' or `~user'
+                [[ -r $j ]] && kh+=( "$j" )
+            done
         done
-        IFS=$OIFS
     fi
 
     if [[ -z $configfile ]]; then
diff --git a/test/fixtures/_known_hosts_real/config_tilde b/test/fixtures/_known_hosts_real/config_tilde
index 1068e29..0893515 100644
--- a/test/fixtures/_known_hosts_real/config_tilde
+++ b/test/fixtures/_known_hosts_real/config_tilde
@@ -1,4 +1,4 @@
 # With quotes and tilde
 UserKnownHostsFile "~/fixtures/_known_hosts_real/known_hosts2"
-# Without quotes, with tilde
-UserKnownHostsFile ~/fixtures/_known_hosts_real/known_hosts3
+# Without quotes, with tilde, and another on the same line
+UserKnownHostsFile ~/fixtures/_known_hosts_real/known_hosts3 fixtures/_known_hosts_real/known_hosts4
diff --git a/test/fixtures/_known_hosts_real/known_hosts4 b/test/fixtures/_known_hosts_real/known_hosts4
new file mode 100644
index 0000000..8510665
--- /dev/null
+++ b/test/fixtures/_known_hosts_real/known_hosts4
@@ -0,0 +1 @@
+four
diff --git a/test/unit/_known_hosts_real.exp b/test/unit/_known_hosts_real.exp
index d4ba804..30ede41 100644
--- a/test/unit/_known_hosts_real.exp
+++ b/test/unit/_known_hosts_real.exp
@@ -80,7 +80,8 @@ set test "Files starting with tilde (~) should work"
 set hosts [get_hosts -unsorted]
     # Hosts `two*' are defined in ./fixtures/_known_hosts_real/known_hosts2
     # Host `three' is defined in ./fixtures/_known_hosts_real/known_hosts3
-lappend hosts two two2 two3 two4 three
+    # Host `four' is defined in ./fixtures/_known_hosts_real/known_hosts4
+lappend hosts two two2 two3 two4 three four
 set hosts [join [bash_sort $hosts] "\\s+"]
     # Setup environment
 set cmd {OLDHOME=$HOME; HOME=$SRCDIRABS}

-- 
bash-completion



More information about the Bash-completion-commits mailing list