Last active
March 28, 2019 18:25
-
-
Save timotheemoulin/d14d8e0bf8e56e997bdaf28ac4befb52 to your computer and use it in GitHub Desktop.
SSH config files compilation from multiple files
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
# Include this snippet in your .zshrc or .bashrc file to compile multiple ssh config files into one. | |
# Put the file anywhere and source it from your .zshrc or .bashrc file with : source /path/to/ssh-compile | |
# This can be useful if you share a config file among several people like in your company and also some private hosts. | |
# call ssh-compile-config to get all the files matching ~/.ssh/.config* and combine them into the final ~/.ssh/config file | |
alias ssh-compile-config='echo -n > ~/.ssh/.config && cat ~/.ssh/config* > ~/.ssh/.config' | |
ssh-compile-config | |
# fetch all the configured hosts | |
h=() | |
if [[ -r ~/.ssh/.config ]]; then | |
ssh-compile-config | |
h=($h ${${${(@M)${(f)"$(cat ~/.ssh/.config)"}:#Host *}#Host }:#*[*?]*}) | |
fi | |
# use all your configured hosts for ssh, slogin, scp, or rsync commands | |
if [[ $#h -gt 0 ]]; then | |
zstyle ':completion:*:ssh:*' hosts $h | |
zstyle ':completion:*:slogin:*' hosts $h | |
zstyle ':completion:*:scp:*' hosts $h | |
zstyle ':completion:*:rsync:*' hosts $h | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment