ssh.completion.bash: parse "Host" directives from all config files
The ssh config can include other files using "Include". The previous code was not taking this into consideration.pull/1015/head
parent
702d923054
commit
b3688b39d8
|
|
@ -11,11 +11,16 @@ _sshcomplete() {
|
||||||
local OPTIONS=" -- ${CURRENT_PROMPT}"
|
local OPTIONS=" -- ${CURRENT_PROMPT}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Parse defined hosts from all ssh configuration files (taking "Include" directives into consideration).
|
||||||
# parse all defined hosts from .ssh/config
|
# The solution relies on ssh printing the configuration files paths in verbose mode.
|
||||||
if [ -r "$HOME/.ssh/config" ]; then
|
#
|
||||||
COMPREPLY=($(compgen -W "$(grep ^Host "$HOME/.ssh/config" | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) )
|
# We try to connect to localhost on port 4, which is reserved and should be unused.
|
||||||
fi
|
# In case there is an ssh server listening on that port, we ask ssh to "do nothing" by executing "echo" remotely.
|
||||||
|
config_files="$(ssh -v 127.0.0.1 -p 4 echo 2>&1 | sed -n '/Reading configuration data/ s/.*Reading configuration data \([^\r]*\).*/\1/gp')"
|
||||||
|
for file in $config_files
|
||||||
|
do
|
||||||
|
COMPREPLY=(${COMPREPLY[@]} $(compgen -W "$(grep ^Host "${file}" | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) )
|
||||||
|
done
|
||||||
|
|
||||||
# parse all hosts found in .ssh/known_hosts
|
# parse all hosts found in .ssh/known_hosts
|
||||||
if [ -r "$HOME/.ssh/known_hosts" ]; then
|
if [ -r "$HOME/.ssh/known_hosts" ]; then
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue