Skip to content

Instantly share code, notes, and snippets.

@lifeofguenter
Created November 10, 2017 09:48
Show Gist options
  • Save lifeofguenter/10a71f7af123e0c4b694729944f88f48 to your computer and use it in GitHub Desktop.
Save lifeofguenter/10a71f7af123e0c4b694729944f88f48 to your computer and use it in GitHub Desktop.
~/.bash_completion.d/
# http://fahdshariff.blogspot.co.za/2011/04/writing-your-own-bash-completion.html
# https://unix.stackexchange.com/a/181603/111459
_ssh() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts=$(grep --no-messages '^Host' ~/.ssh/config ~/.ssh/config.d/* | grep -v '[?*]' | cut -d ' ' -f 2-)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
complete -F _ssh ssh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment