Skip to content

Instantly share code, notes, and snippets.

@thyme-87
Created October 10, 2018 13:35
Show Gist options
  • Save thyme-87/36fe823e4c54dc8bb9a658a4cfa42fae to your computer and use it in GitHub Desktop.
Save thyme-87/36fe823e4c54dc8bb9a658a4cfa42fae to your computer and use it in GitHub Desktop.
SSH autocomplete based on ~/.ssh/config for broken beyond repair and beneath contempt OSX
##autocomplete ssh
#Thanks to: https://gist.github.com/magnetikonline/bcd4186e14ed02145390
function _completeSSHHosts {
COMPREPLY=()
local currentWord=${COMP_WORDS[COMP_CWORD]}
local completeHosts=$(
cat "$HOME/.ssh/config" | \
grep --extended-regexp --regexp "^(Host|host) +[^* ]+? *$" | \
tr -s " " | cut -d " " -f 2;
cat /etc/hosts | \
grep --extended-regexp --regexp "^[0-9]{3}\." | \
awk "{print \$2}"
)
COMPREPLY=($(compgen -W "$completeHosts" -- "$currentWord"))
return 0
}
complete -F _completeSSHHosts ssh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment