Skip to content

Instantly share code, notes, and snippets.

@Plancke
Last active August 26, 2017 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Plancke/3dcd9a324ef58b00c2f0ac696c88d542 to your computer and use it in GitHub Desktop.
Save Plancke/3dcd9a324ef58b00c2f0ac696c88d542 to your computer and use it in GitHub Desktop.
# Modified from https://gist.github.com/aliang/1024466
# Recursively greps config.d for ssh configs using the
# OpenSSH 7.3p1 (https://www.openssh.com/txt/release-7.3) Include directive
# Original script didn't do this, hence my modification
# I included an exclude for "*.txt" files since I generate my ssh configs using SaltStack
# and I move old files to ./old/{DATE}.txt, in case anything goes wrong (salt minion dead, etc)
# Feel free to modify this however you see fit of course.
# I also modified the cut line to just use awk as per recommendation of
# https://gist.github.com/aliang/1024466#gistcomment-1868997
# Put this in .bash_profile
_complete_ssh_hosts() {
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
comp_ssh_hosts=$(
awk '{split($1,aliases,","); if (aliases[1] !~ /^\[/) print aliases[1]}' ~/.ssh/known_hosts ;
grep -r --exclude="*.txt" "^Host " ~/.ssh/config.d/ | grep -v "*" | awk '{print $2}'
)
COMPREPLY=( $(compgen -W "${comp_ssh_hosts}" -- "$cur"))
return 0
}
complete -F _complete_ssh_hosts ssh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment