From 4a25fd0cec0477e395049e5ad41d9c59a2da969f Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Mon, 3 Aug 2015 12:58:36 +0200 Subject: [PATCH] Support ssh config.d, generating ~/.ssh/config from files in ~/.ssh/config.d/, preserving order --- .bashrc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.bashrc b/.bashrc index 96ed0e4..ca6aefb 100644 --- a/.bashrc +++ b/.bashrc @@ -166,6 +166,21 @@ xterm*|rxvt*) ;; esac +# SSH config merge +#mkdir -p ~/.ssh/config.d/ +if [ -e ~/.ssh/config.d ]; then + #if find ~/.ssh/config.d -mindepth 1 -print -quit | grep -q .; then + if find ~/.ssh/config.d -print -quit | grep -q .; then + #newestconfig=$(ls -t ~/.ssh/config.d/ | head -1) + newestconfig=$(find ~/.ssh/config.d/* -printf '%T+ %p\n' | sort -r | head -n1 | awk '{print $2}') + if [ "$newestconfig" -nt ~/.ssh/config ]; then + [ -e ~/.ssh/config ] && mv ~/.ssh/config ~/.ssh/config.bak.$(date -Ins) + #cat ~/.ssh/config.d/* > ~/.ssh/config + find ~/.ssh/config.d/* -type f -print0 | sort -z | xargs -0 -n1 cat > ~/.ssh/config + fi + fi +fi + # Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly.