Snippet for ~/.bash_profile
, adding hostname autocomplete to ssh
and scp
.
Extracts host hints from ~/.ssh/config
.
function __completeSSHHosts {
COMPREPLY=()
local currentWord=${COMP_WORDS[COMP_CWORD]}
local completeHosts=$(
cat "$HOME/.ssh/config" | \
grep --extended-regexp "^Host +([^* ]+ +)*[^* ]+ *$" | \
tr -s " " | \
sed -E "s/^Host +//"
)
COMPREPLY=($(compgen -W "$completeHosts" -- "$currentWord"))
}
complete -F __completeSSHHosts scp ssh