-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreflex
More file actions
executable file
·50 lines (39 loc) · 751 Bytes
/
reflex
File metadata and controls
executable file
·50 lines (39 loc) · 751 Bytes
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
#!/bin/bash
# Watches for changes and runs a command
#
# Watches current directory by default by can pass a file name or a directory
# to watch
# Depends on inotify-tools
set -o nounset
set -o errexit
## VARIABLES
FORMAT="%%w%%f modified"
FILE="."
COMMAND=$@
## FUNCTIONS
usage() {
printf "Usage: reflex [file|directory] <command>\n"
exit 1
}
print() {
printf "\033[1;33m[reflex]\033[0m $1"
}
run() {
print "running $COMMAND\n"
eval "$COMMAND"
}
## ARG CHECK
if [[ $# == 0 ]]; then usage; fi
if [[ $# -ge 2 ]]; then
FILE="$1"
COMMAND="${@:2}"
if [[ ! -e $FILE ]]; then usage; fi
fi
## MAIN
# Run command
run || true
# Loop
while true; do
inotifywait -qr --event modify --format "$(print $FORMAT)" $FILE
run || true
done