diff --git a/collect.sh b/collect.sh new file mode 100644 index 0000000..caeb5de --- /dev/null +++ b/collect.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# machine -> repo: copy current ~/.config files into config/ +# Only files that already exist under config/ are collected, +# so nothing gets tracked by accident. +set -euo pipefail + +repo="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +dst="$repo/config" + +shopt -s nullglob dotglob +count=0 +missing=0 +while IFS= read -r -d '' f; do + rel="${f#"$dst"/}" + src="$HOME/.config/$rel" + if [ ! -f "$src" ]; then + echo "missing on this machine: $rel (skipped)" + missing=$((missing + 1)) + continue + fi + if cmp -s "$src" "$f"; then + echo "unchanged: $rel" + else + cp -a "$src" "$f" + echo "collected: $rel" + fi + count=$((count + 1)) +done < <(find "$dst" -type f -print0) + +echo "done: $count tracked file(s) checked, $missing missing" +echo "review with: git -C '$repo' diff"