Skip to content

Commit

Permalink
Merge pull request #7 from ukleinek/master
Browse files Browse the repository at this point in the history
Don't complete hostnames found after Hostname in ~/.ssh/config
  • Loading branch information
scop committed Feb 26, 2016
2 parents c4517d3 + 4621117 commit 293ddb7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ _known_hosts_real()

# append any available aliases from config files
if [[ ${#config[@]} -gt 0 && -n "$aliases" ]]; then
local hosts=$( command sed -ne 's/^['"$'\t '"']*[Hh][Oo][Ss][Tt]\([Nn][Aa][Mm][Ee]\)\{0,1\}['"$'\t '"']\{1,\}\([^#*?%]*\)\(#.*\)\{0,1\}$/\2/p' "${config[@]}" )
local hosts=$( command sed -ne 's/^['"$'\t '"']*[Hh][Oo][Ss][Tt]['"$'\t '"']\{1,\}\([^#*?%]*\)\(#.*\)\{0,1\}$/\1/p' "${config[@]}" )
COMPREPLY+=( $( compgen -P "$prefix$user" \
-S "$suffix" -W "$hosts" -- "$cur" ) )
fi
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/scp/config
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ UserKnownHostsFile known_hosts
Host gee
# Indented, multiple hosts
HostName hus ike

Host hut
2 changes: 2 additions & 0 deletions test/fixtures/sftp/config
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ UserKnownHostsFile known_hosts
Host gee
# Indented, multiple hosts
HostName hus ike

Host hut
4 changes: 2 additions & 2 deletions test/lib/completions/scp.exp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ set test "Tab should complete known-hosts"

# Build string list of expected completions
# Get hostnames and give them a colon (:) suffix
# Hosts `gee' and `hus' are defined in ./fixtures/scp/config
# Hosts `gee' and `hut' are defined in ./fixtures/scp/config
# Hosts `blah', `doo' and `ike' are defined in ./fixtures/scp/known_hosts
set expected {}
foreach host [get_hosts] {
lappend expected "$host:"
}
lappend expected blah: doo: gee: hus: ike:
lappend expected blah: doo: gee: hut: ike:
# Append local filenames
lappend expected config known_hosts "spaced\\ \\ conf"
assert_complete $expected "scp -F config " $test
Expand Down
8 changes: 4 additions & 4 deletions test/lib/completions/sftp.exp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ setup

# Build string list of expected completions
set expected [get_hosts]
# Hosts `gee' and `hus' are defined in ./fixtures/sftp/config
# Hosts `gee' and `hut' are defined in ./fixtures/sftp/config
# Hosts `10.10.10.10', `doo' and `ike' are defined in ./fixtures/sftp/known_hosts
lappend expected 10.10.10.10 doo gee hus ike
lappend expected 10.10.10.10 doo gee hut ike
assert_complete $expected "sftp -F config "


Expand All @@ -48,9 +48,9 @@ sync_after_int
# Build string list of expected completions
# Get hostnames and give them a colon (:) suffix
set expected [get_hosts]
# Hosts `gee', `hus' and `jar' are defined in "./fixtures/sftp/spaced conf"
# Hosts `gee' and `jar' are defined in "./fixtures/sftp/spaced conf"
# Hosts `10.10.10.10', `doo' and `ike' are defined in ./fixtures/sftp/known_hosts
lappend expected 10.10.10.10 doo gee hus ike jar
lappend expected 10.10.10.10 doo gee ike jar
assert_complete $expected "sftp -F spaced\\ \\ conf "


Expand Down

0 comments on commit 293ddb7

Please sign in to comment.