Created
October 10, 2018 13:35
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##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