-
-
Save spacegaucho/dffb3139f5219b093f6a2253fcfccb57 to your computer and use it in GitHub Desktop.
Bash completion for ssh
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
# Store in /etc/bash_completion.d/ssh | |
# Create a ~/.ssh/hosts file that includes the hostnames you want to autocomplete | |
# Example: `Host hostname` | |
# Found this idea here https://unix.stackexchange.com/a/181603 | |
_ssh() | |
{ | |
local cur prev opts | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
opts=$(grep '^Host' ~/.ssh/config ~/.ssh/hosts| grep -v '[?*]' | cut -d ' ' -f 2-) | |
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) | |
return 0 | |
} | |
complete -F _ssh ssh | |
# You can add any aliases that do different things here too | |
# complete -F _ssh sshalias |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment