summaryrefslogtreecommitdiffstats
path: root/onchange
blob: 5326d1771ec850696b066cdf49d166bfcae8306e (plain)
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
#!/bin/bash

declare -a files
declare -a command

num_args=$#
parameters_done=0
for (( i = 0; i < num_args; i++ )); do
	case "$1" in
		--)
			parameters_done=1
			shift
			;;
		*)
			if ((parameters_done)); then
				command+=("$1")
			else
				files+=("$1")
			fi
			shift
			;;
	esac
done

echo "files: ${files[*]}"
echo "command: ${command[*]}"

while inotifywait -e close_write "${files[@]}"; do
	"${command[@]}"
done