forked from obszczymucha/roll-for-vanilla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-vanilla.sh
More file actions
executable file
·85 lines (73 loc) · 1.92 KB
/
sync-vanilla.sh
File metadata and controls
executable file
·85 lines (73 loc) · 1.92 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
TARGET_DIR="$HOME/.projects/lua/wow-1.12.1-addons.git/master"
function sync() {
echo "Syncing addons with ${TARGET_DIR}..." >&2
rsync -ah RollFor "$TARGET_DIR"
}
function listen() {
echo "Listening..." >&2
# The 4 digit regex deals with temporary neovim files.
inotifywait -mqre create,close_write,delete,move --format "%e %w%f" --exclude '/[0-9]{4}$' . | while read -r event filename; do
local name
name=$(echo "$filename" | sed -E 's/^\.\///g')
if [[ "$name" != *~ ]]; then
on_change "$event" "$name"
fi
done
}
function on_change() {
local event="$1"
local filename="$2"
if [[ "$filename" == "test/"* ]]; then
echo "Ignoring test: $filename" >&2
return
fi
if [[ "$filename" != "RollFor/"* ]]; then
echo "Ignoring non-addon file: $filename" >&2
return
fi
case "$event" in
"CREATE,ISDIR")
echo "Creating directory: $filename" >&2
mkdir -p "${TARGET_DIR}/$filename"
;;
"DELETE,ISDIR"|"MOVED_FROM,ISDIR")
echo "Deleting directory: $filename" >&2
rm -rf "${TARGET_DIR:?}/$filename"
;;
"MOVED_TO,ISDIR")
echo "Renaming directory: $filename" >&2
cp -r "$filename" "${TARGET_DIR}/$filename"
;;
"CREATE")
# We ignore this, if the file is written, another event follows up.
;;
"CLOSE_WRITE,CLOSE")
echo "Modifying file: $filename" >&2
cp "$filename" "${TARGET_DIR}/$filename"
;;
"DELETE"|"MOVED_FROM")
echo "Deleting file: $filename" >&2
rm "${TARGET_DIR}/$filename"
;;
"MOVED_TO")
echo "Renaming file: $filename" >&2
cp "$filename" "${TARGET_DIR}/$filename"
;;
*)
echo "Implement me! Event: $event" >&2
;;
esac
}
function main() {
if [[ -z "$TARGET_DIR" ]]; then
echo "TARGER_DIR is invalid." >&2
exit 1
fi
if [[ $# -eq 0 ]]; then
tmux rename-window "sync"
fi
sync
listen
}
main "$@"