1 | #!/usr/bin/env bash
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | path=$1
|
12 | type sha1sum 2> /dev/null
|
13 | if [ $? -eq 0 ]; then
|
14 | shasum=sha1sum
|
15 | else
|
16 | shasum=shasum
|
17 | fi
|
18 |
|
19 | shift
|
20 | cmd=${*:1}
|
21 | sha=0
|
22 | update_sha() {
|
23 |
|
24 | sha=`ls -lR $path | $shasum`
|
25 | }
|
26 | update_sha
|
27 | previous_sha=$sha
|
28 | build() {
|
29 | echo -en "\n running -> ${cmd[@]}\n\n"
|
30 | eval ${cmd[@]}
|
31 | echo -en "\n--> resumed watching."
|
32 | }
|
33 | compare() {
|
34 | update_sha
|
35 | if [[ $sha != $previous_sha ]] ; then
|
36 | echo -n "change detected,"
|
37 | build
|
38 | previous_sha=$sha
|
39 | else
|
40 | echo -n .
|
41 | fi
|
42 | }
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | build
|
48 | echo -e "--> Press Ctrl+C to exit."
|
49 | echo -en "--> watching \"$path\"."
|
50 | while true; do
|
51 | compare
|
52 | sleep 1
|
53 | done
|