Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Watches a diretory and runs a command on save changes.
#!/bin/bash
if [ ! "$1" ]; then
cat << EOF
$0 -- Watch a directory and run a command on changes
$0 cmd options
Environmental vars:
WATCHDIR -- Direcotry to watch, by default current
EOF
exit 0
fi
WATCHDIR=$1
shift 1
while true; do
echo -e "\e[6;37;46m \n \n$*\n \e[0m"
sh -c "$*"
exit_code=$?
if [ "$exit_code" = 0 ]; then
echo -e "\e[6;37;44m\nEXIT $?\e[0m"
else
echo -e "\e[6;37;41m\nEXIT $?\e[0m"
fi
echo
sleep 1
inotifywait -re close_write $WATCHDIR
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment