diff --git a/apply.sh b/apply.sh new file mode 100644 index 0000000..987dbc7 --- /dev/null +++ b/apply.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# repo -> machine: copy tracked files from config/ into ~/.config +# Overwrites existing files, keeping a timestamped .bak of each. +set -euo pipefail + +src="$(cd "$(dirname "${BASH_SOURCE[0]}")/config" && pwd)" +stamp="$(date +%Y%m%d-%H%M%S)" + +shopt -s nullglob dotglob +count=0 +while IFS= read -r -d '' f; do + rel="${f#"$src"/}" + dest="$HOME/.config/$rel" + mkdir -p "$(dirname "$dest")" + if [ -e "$dest" ] && ! cmp -s "$f" "$dest"; then + cp -a "$dest" "$dest.bak-$stamp" + echo "backed up: $dest -> $dest.bak-$stamp" + fi + cp -a "$f" "$dest" + echo "applied: $rel" + count=$((count + 1)) +done < <(find "$src" -type f -print0) + +echo "done: $count file(s) applied to ~/.config"