Last active
August 26, 2017 09:44
-
-
Save Plancke/3dcd9a324ef58b00c2f0ac696c88d542 to your computer and use it in GitHub Desktop.
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
# 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