Created
May 13, 2013 22:02
-
-
Save papaben/5571891 to your computer and use it in GitHub Desktop.
The bash completion file I'm using for ssh and scp
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
## | |
# Complete SSH with known hosts or configured hosts | |
## | |
_complete_ssh_hosts () | |
{ | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
comp_ssh_hosts=$(if [ -f ~/.ssh/known_hosts ]; then | |
cat ~/.ssh/known_hosts | \ | |
cut -f 1 -d ' ' | \ | |
sed -e s/,.*//g | \ | |
grep -v ^# | \ | |
uniq | \ | |
grep -v "\[" ; | |
fi | |
if [ -f ~/.ssh/config ]; then | |
cat ~/.ssh/config | \ | |
grep "^Host " | \ | |
awk '{print $NF}' | |
fi | |
) | |
COMPREPLY=( $(compgen -W "${comp_ssh_hosts}" -- $cur)) | |
return 0 | |
echo "$comp_ssh_hosts" | |
} | |
# Auto-complete with, | |
# * file names, | |
# * entries from hostfile, | |
# * results of _complete_ssh_hosts | |
complete \ | |
-A file \ | |
-A hostname \ | |
-F _complete_ssh_hosts \ | |
ssh scp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment