Skip to content

Instantly share code, notes, and snippets.

@ro31337
Last active May 20, 2018 22:26
Show Gist options
  • Save ro31337/8f9104529b06dfa315bb068c6ed8bdbf to your computer and use it in GitHub Desktop.
Save ro31337/8f9104529b06dfa315bb068c6ed8bdbf to your computer and use it in GitHub Desktop.
Run "ruby" over file when file changes (useful for vim + tmux panes, or other tiled window setup. Make sure you +x this script)
#!/bin/bash
#
# Usage: ./ruby-it-on-file-change.sh app.rb
# ^ Will automatically run "ruby app.rb" when file changes
#
echo "Watching for changes in $1, save this file to run \"ruby $1\""
if uname | grep -q "Darwin"; then
mod_time_fmt="-f %m"
else
mod_time_fmt="-c %Y"
fi
### Set initial time of file
LTIME=`stat $mod_time_fmt $1`
while true
do
ATIME=`stat $mod_time_fmt $1`
if [[ "$ATIME" != "$LTIME" ]]
then
NOW=`date +"%H:%M:%S"`
echo "RUN COMMAND AT $NOW"
LTIME=$ATIME
ruby $1
fi
sleep 0.1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment