2019-09-05T21:25:32

watchfolder & execute on change

Short script to execute some commend when folder changes.

:~$ cat bin/watchfolder 
#!/bin/bash

if [ ! $1 ]; then
	echo 'Usage: watchfolder CMD'
	echo
	echo '	Everytime some files or folders change under $PWD'
	echo '  the CMD command is executed'
	exit 1
fi

$@

WATCH=.; while E=`inotifywait -r -e modify,create $WATCH`; do echo $E; $@; echo -e 'done\n'; done

Can be made to execute `make` in current folder, or compile and/or execute a script or run tests when editing folder structure.

For Debian `apt-get install inotify-tools` is needed.

comments powered by Disqus