-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_dotfiles
executable file
·62 lines (51 loc) · 1.41 KB
/
check_dotfiles
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# Compare the list of dot files in $HOME with an allow list and a forbidden
# list, and update the lists or delete the files. Make it faster to answer "do I
# have all my dotfiles checked in?".
set -e
set -u
REMOVE_LIST="${XDG_CONFIG_HOME:-$HOME}"/dotfiles.remove
ALLOW_LIST="${XDG_CONFIG_HOME:-$HOME}"/dotfiles.allowed
touch "$ALLOW_LIST"
touch "$REMOVE_LIST"
# Removing known forbidden files that keep reappearing.
trash_forbidden(){
while read -r file; do
(trash "$file" 2>/dev/null && printf "Trashed %s\n" "$file...") || true
done < "$REMOVE_LIST"
}
trash_forbidden
file="/home/hiq/.FBReader"
find "$HOME" -maxdepth 1 -name '\.*' | sort | while read -r file ; do
if grep -q "$file" "$ALLOW_LIST"; then
continue
fi
if grep -q "$file" "$REMOVE_LIST"; then
continue
fi
printf "File: %s not in any list\n" "$file"
# Subshell required to make the select compatible with the while loop.
(
select choice in "Add to allow list" "Add to remove list" "Do nothing"; do
case $choice in
"Add to allow list")
echo "Add to allow list."
printf "%s\n" "$file" >> "$ALLOW_LIST"
break
;;
"Add to remove list")
echo "Add to remove list."
printf "%s\n" "$file" >> "$REMOVE_LIST"
break
;;
*)
echo "$choice"
echo Doing nothing.
break
;;
esac
done
) < /dev/tty
done
# To remove files added to remove list in the meantime.
trash_forbidden