Created
June 18, 2019 10:48
-
-
Save palawer/8463c0d0f0017870e2b631bf7c8e78bb to your computer and use it in GitHub Desktop.
Autocomplete SSH hosts
This file contains hidden or 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
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")) | |
return 0 | |
} | |
complete -F __completeSSHHosts ssh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment