forked from waterlink/mocks.cr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch.sh
executable file
·56 lines (49 loc) · 1.39 KB
/
watch.sh
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
#!/usr/bin/env bash
AUTO_COMMIT=${AUTO_COMMIT:-""}
os="$(uname)"
next_change() {
x=$(cat .change-count)
echo $((x+1)) | tee .change-count
}
watch() {
if [[ "$os" = "Linux" ]]; then
# to install: apt-get install inotify-tools
inotifywait --quiet --recursive --monitor --event modify --format "%w%f" "$@"
elif [[ "$os" = "Darwin" ]]; then
# to install: brew install fswatch
fswatch -o "$@"
else
echo "Unknown OS $os"
exit 1
fi
}
notify() {
if [[ "$os" = "Linux" ]]; then
notify-send "$@"
elif [[ "$os" = "Darwin" ]]; then
# to install: brew install terminal-notifier
if [[ "$1" == --expire-time=* ]]; then
shift
fi
echo terminal-notifier -message "$@"
terminal-notifier -message "$@"
else
echo "Unknown OS $os"
exit 1
fi
}
watch src spec \
| while read change; do
crystal spec --no-color > .watch.out
res=$?
committed=
if [[ $res -eq 0 ]]; then
! [[ -z "$AUTO_COMMIT" ]] && git add . && git commit -m "[GREEN] Change $(next_change)" && committed="(committed)"
notify --expire-time=1000 "SUCCESS $committed"
else
failure=$(cat .watch.out | grep 'Failure\|expected:\|got:\|Error in')
cat .watch.out
! [[ -z "$AUTO_COMMIT" ]] && git add . && git commit -m "[RED] Change $(next_change)" && committed="(committed)"
notify --expire-time=3000 "FAILURE:$failure $committed"
fi
done