Last active
January 4, 2016 19:29
-
-
Save jtopper/8667226 to your computer and use it in GitHub Desktop.
Autocomplete known ssh hosts and filenames when using ssh or 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
# Add this to .profile or .bashrc | |
_complete_ssh() { | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
local hosts=$(awk -F'[ ,]' '{ print $1 }' ~/.ssh/known_hosts | sort -u) | |
COMPREPLY=( $(compgen -W "${hosts}" -- ${cur}) ) | |
} | |
complete -o default -F _complete_ssh ssh scp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment