-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwatch
executable file
·44 lines (39 loc) · 1.09 KB
/
watch
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
#!/bin/sh
# This script will recompile a rust project using `make`
# every time something in the specified directory changes.
#
# It is designed to be used in a rust-empty style crate.
# $1: Directory to watch
# src by default
# $2: Command to execute
# `make` by default
# Determine target architecture
TARGET=`rustc --version 2> /dev/null | awk '/host:/ { FS = " "; print $2 }'`
# Watch files in infinite loop
watch () {
if [ -e "$1" ]; then
echo "Watching files in $1.."
CTIME=$(date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s")
while :; do
sleep 1
for f in `find $1 -type f -name "*.rs"`; do
eval $(stat -s $f)
if [ $st_mtime -gt $CTIME ]; then
CTIME=$(date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s")
echo Rebuilding:
echo '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
$2
if [ ! $? -eq 0 ]; then
echo ""
fi
fi
done
done
else
echo "$1 is not a valid directory"
fi
}
# Capture user input with defaults
DIR=${1:-src}
CMD=${2:-make}
watch "$DIR" "$CMD"