Skip to content

Instantly share code, notes, and snippets.

@laggage
Created January 11, 2022 02:52
Show Gist options
  • Save laggage/6c800738ac5eb0a951a65488a1d55f59 to your computer and use it in GitHub Desktop.
Save laggage/6c800738ac5eb0a951a65488a1d55f59 to your computer and use it in GitHub Desktop.
ssh autocomplete
_ssh()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts=$(grep '^Host' ~/.ssh/config ~/.ssh/config.d/* 2>/dev/null | 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