|
|
@ -0,0 +1,57 @@
|
|
|
1
|
#!/bin/bash
|
|
|
2
|
|
|
|
3
|
TARGET="$HOME/d/history-$(date +%Y-%m)"
|
|
|
4
|
|
|
|
5
|
echo "Archiving files (and directories in) $PWD to $TARGET"
|
|
|
6
|
mkdir --parent "$TARGET"
|
|
|
7
|
|
|
|
8
|
DRY_RUN="yes"
|
|
|
9
|
if [ "$1" = "--no-dry-run" ]; then
|
|
|
10
|
DRY_RUN="no"
|
|
|
11
|
shift
|
|
|
12
|
fi
|
|
|
13
|
|
|
|
14
|
MV_STYLE="--interactive"
|
|
|
15
|
if [ "$1" = "--no-clobber" ]; then
|
|
|
16
|
MV_STYLE="--no-clobber"
|
|
|
17
|
shift
|
|
|
18
|
fi
|
|
|
19
|
|
|
|
20
|
ignored=".local\n.cache\n$(git ls-files)"
|
|
|
21
|
|
|
|
22
|
for file in $(find . -maxdepth 1 -name '.*' -printf '%P\n' | sort); do
|
|
|
23
|
if echo "$ignored" | grep "$file" > /dev/null; then
|
|
|
24
|
continue
|
|
|
25
|
fi
|
|
|
26
|
|
|
|
27
|
size=$(du -s -b "$file" | cut -f1)
|
|
|
28
|
echo "$file = $size"
|
|
|
29
|
if [ "$size" -lt "1000000" ]; then
|
|
|
30
|
echo mv --verbose "$MV_STYLE" "$file" "$TARGET/$file"
|
|
|
31
|
[ "$DRY_RUN" = "no" ] && mv --verbose "$MV_STYLE" "$file" "$TARGET/$file"
|
|
|
32
|
else
|
|
|
33
|
echo "$file is too big ($size)"
|
|
|
34
|
echo -n "What to do? ((a)rchive/(rm)remove/(s)kip): "
|
|
|
35
|
if [ "$DRY_RUN" = "yes" ]; then
|
|
|
36
|
echo "dry run"
|
|
|
37
|
continue
|
|
|
38
|
fi
|
|
|
39
|
read answer
|
|
|
40
|
case "$answer" in
|
|
|
41
|
a|archive)
|
|
|
42
|
echo mv --verbose "$MV_STYLE" "$file" "$TARGET/$file"
|
|
|
43
|
mv --verbose "$MV_STYLE" "$file" "$TARGET/$file"
|
|
|
44
|
;;
|
|
|
45
|
rm|remove)
|
|
|
46
|
echo rm --recursive --interactive=once "$file"
|
|
|
47
|
rm --verbose --recursive --interactive=once "$file"
|
|
|
48
|
;;
|
|
|
49
|
s|skip)
|
|
|
50
|
echo "skipping $file"
|
|
|
51
|
;;
|
|
|
52
|
*)
|
|
|
53
|
echo "unknown command '$answer', skipping"
|
|
|
54
|
;;
|
|
|
55
|
esac
|
|
|
56
|
fi
|
|
|
57
|
done
|