Skip to content

Commit 0486a11

Browse files
authored
fix(_known_hosts_real): remove empty hostnames (scop#737)
Fix the problem mentioned in Ref [1]. This is a regression caused by commit 08dd2cd [2]. When there is an entry "Host *" in ssh_config, an empty hostname is generated. We exclude the empty completions using the compgen option "-X". The empty hostname manifests typically with `scp <TAB>`, which before this fix gave `scp :`. [1] scop#720 (comment) [2] \ scop@08dd2cd#diff-a4757074ff650000804fd3eaabe9b0a9e02e33040ca5b8afd4c0275fc5f3e136R1886
1 parent 8181dab commit 0486a11

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

bash_completion

+1-1
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ _known_hosts_real()
19241924
local -a hosts=($(command sed -ne 's/^[[:blank:]]*[Hh][Oo][Ss][Tt][[:blank:]=]\{1,\}\(.*\)$/\1/p' "${config[@]}"))
19251925
if ((${#hosts[@]} != 0)); then
19261926
COMPREPLY+=($(compgen -P "$prefix" \
1927-
-S "$suffix" -W '"${hosts[@]%%[*?%]*}"' -X '\!*' -- "$cur"))
1927+
-S "$suffix" -W '"${hosts[@]%%[*?%]*}"' -X '@(\!*|)' -- "$cur"))
19281928
fi
19291929
fi
19301930

test/fixtures/_known_hosts_real/config

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
UserKnownHostsFile _known_hosts_real/known_hosts
22

33
# Unindented
4+
Host *
5+
IPQoS none
46
Host gee* jar?this-part-we-do-not-complete-at-least-yet
57
HostName %h.example.com
68
# Indented, with = separator

0 commit comments

Comments
 (0)