Skip to content

Instantly share code, notes, and snippets.

@avoidik
Created May 14, 2023 12:41
Show Gist options
  • Select an option

  • Save avoidik/a68f38aaca0e73dff4e4eb39050fb770 to your computer and use it in GitHub Desktop.

Select an option

Save avoidik/a68f38aaca0e73dff4e4eb39050fb770 to your computer and use it in GitHub Desktop.
Autocompletion for SSH hosts
_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
@avoidik
Copy link
Author

avoidik commented May 14, 2023

mkdir -p ~/.ssh/config.d
sed -i '1s;^;Include config.d/*;' ~/.ssh/config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment