Last active
November 25, 2021 13:52
-
-
Save srpatel/4ab0ffb532569383f795 to your computer and use it in GitHub Desktop.
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
# Source this file in your .profile/.bashrc in order to get tab autocomplete | |
# on ssh hosts as listed in your ~/.ssh/config file. | |
_ssh_autocomplete() { | |
local SSH_CONFIG_FILE="$HOME/.ssh/config" | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
if [[ "$COMP_CWORD" -eq "1" && -f $SSH_CONFIG_FILE ]]; then | |
local hosts=`cat $SSH_CONFIG_FILE | grep ^Host | awk '{ $1=""; print $0 }' | tr '\n' ' '` | |
COMPREPLY=( $(compgen -W "$hosts" -- $cur) ) | |
else | |
COMPREPLY=( $(compgen -o nospace -f ${cur}) ); #normal | |
fi | |
} | |
complete -F _ssh_autocomplete ssh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment