Skip to content

Instantly share code, notes, and snippets.

@genewoo
Created August 23, 2013 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genewoo/6321290 to your computer and use it in GitHub Desktop.
Save genewoo/6321290 to your computer and use it in GitHub Desktop.
Watch File or Files changed in a folder to run a command
#!/bin/bash
# watchdo "rake" .rb
command="$1"
shift
fileSpec="$@"
sentinel=/tmp/t.$$
touch -t197001010000 $sentinel
while :
do
files=$(find . -newer $sentinel -a '(' -name "*$fileSpec" ')')
if [ $? != 0 ]; then
exit 1;
fi
#echo $files
if [ "$files" != "" ]; then
$command
touch $sentinel
fi
sleep 0.5
done
#!/bin/bash
# watchdoit "ruby" .rb
command="$1"
shift
fileSpec="$@"
sentinel=/tmp/t.$$
touch -t197001010000 $sentinel
while :
do
files=$(find . -newer $sentinel -a '(' -name "*$fileSpec" ')')
if [ $? != 0 ]; then
exit 1;
fi
#echo $files
if [ "$files" != "" ]; then
$command $files
touch $sentinel
fi
sleep 0.5
done
@genewoo
Copy link
Author

genewoo commented Aug 23, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment