-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatcher.sh
executable file
·67 lines (58 loc) · 2.14 KB
/
watcher.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
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
COMPILE="./compile.sh"
TEST="./test"
SUCCESS_ICON="icons/success.svg" # https://commons.wikimedia.org/wiki/File:CrystalClearActionApply.svg
WARNING_ICON="icons/warning.svg" # https://commons.wikimedia.org/wiki/File:Crystal_Clear_app_error.svg
ERROR_ICON="icons/error.svg" # https://commons.wikimedia.org/wiki/File:Crystal_128_error.svg
NOTIFICATION_TIMEOUT=5000 # in milliseconds
function notify {
icon="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/$1"
notify-send -t $NOTIFICATION_TIMEOUT -i $icon "$2" "$3"
}
function run_test {
exec 3>&1 # Save the place that stdout (1) points to.
result=$($TEST 2>&1 1>&3) # Run command. stderr is captured.
failures="$?"
exec 3>&- # Close FD #3.
if [[ $failures -eq 0 ]]; then
notify $SUCCESS_ICON "Tests OK" "All tests passed"
elif [[ $failures -eq 139 ]]; then
# http://arstechnica.com/civis/viewtopic.php?f=16&t=113430
notify $ERROR_ICON "Segmentation fault!" ""
else
notify $ERROR_ICON "$failures tests failed!" "$result"
fi
}
function compile {
exec 3>&1 # Save the place that stdout (1) points to.
out=$($COMPILE 2>&1 1>&3) # Run command. stderr is captured.
failures="$?"
exec 3>&- # Close FD #3.
printf "$out"
if [[ $failures -eq 0 ]]; then
run_test
if grep "warning:" <<<"${out}" >/dev/null ; then
notify $WARNING_ICON "Compilation passed with warnings" ""
fi
else
notify $ERROR_ICON "Compilation Error" "Error compiling"
fi
}
function daemon {
dir=$1
chsum1=""
while [[ true ]]
do
chsum2=$(find $dir \( -iname \*.c -o -iname \*.h \) -type f -exec md5sum {} \;)
if [[ $chsum1 != $chsum2 ]] ; then
echo ""
echo -e "\e[1m=======================================\e[0m"
echo -e "\e[1m============== Compiling ==============\e[0m"
echo -e "\e[1m=======================================\e[0m"
compile
chsum1=$chsum2
fi
sleep 2
done
}
daemon $1