Skip to content

Instantly share code, notes, and snippets.

@timotheemoulin
Last active March 28, 2019 18:25
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 timotheemoulin/d14d8e0bf8e56e997bdaf28ac4befb52 to your computer and use it in GitHub Desktop.
Save timotheemoulin/d14d8e0bf8e56e997bdaf28ac4befb52 to your computer and use it in GitHub Desktop.
SSH config files compilation from multiple files
# 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