From d6558bd6018d6fa713d42311626422a74dcf725f Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Sun, 30 Aug 2026 19:47:17 +0200 Subject: [PATCH] The SSH config generator code as separate script --- bin/ssh_config_gen | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 bin/ssh_config_gen diff --git a/bin/ssh_config_gen b/bin/ssh_config_gen new file mode 100755 index 0000000..54bb721 --- /dev/null +++ b/bin/ssh_config_gen @@ -0,0 +1,17 @@ +#!/bin/bash + +# SSH config merge +if [ -e ~/.ssh/config.d ]; then + #if find ~/.ssh/config.d -mindepth 1 -print -quit | grep -q .; then + # Do we have config files in that directory? + if find ~/.ssh/config.d -print -quit | grep -q .; then + newestconfig=$(find ~/.ssh/config.d/* -printf '%TY-%Tm-%Td %.8TT %p\n' | sort -r | head -n1 | awk '{print $3}') + if [ "$newestconfig" -nt ~/.ssh/config ]; then + # We found a config that's newer than the generated config file, re-generate + [ -e ~/.ssh/config ] && mv ~/.ssh/config ~/.ssh/config.bak.$(date -Is) + # Lets preserve order, so you can have 00_generic 10_homestuff 20_work1 21_work2 and such + find ~/.ssh/config.d/* -type f -print0 | sort -z | xargs -0 -n1 cat > ~/.ssh/config + chmod 600 ~/.ssh/config + fi + fi +fi