add collect.sh
This commit is contained in:
1 parent
ab1102ef55
commit
0ecb52b6e7
1 file changed
+31
+31
@@ -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"
|
||||
Reference in new issue
Block a user