Skip to content

Instantly share code, notes, and snippets.

@ixaxaar
Created January 31, 2019 17:43
Show Gist options
  • Save ixaxaar/f6a421ec5a5fab35c770d10f844f526e to your computer and use it in GitHub Desktop.
Save ixaxaar/f6a421ec5a5fab35c770d10f844f526e to your computer and use it in GitHub Desktop.
#!/bin/sh
###############################################################################################
# Run as ./run_on_save.sh ./file/to/watch ./script/to/run.sh --args --to --give --to --script
###############################################################################################
# get the current path
CURPATH=`pwd`
TO_WATCH=$1
shift
TO_EXEC=$1
shift
inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' \
-e close_write $TO_WATCH | while read date time dir file; do
FILECHANGE=${dir}${file}
# convert absolute path to relative
FILECHANGEREL=`echo "$FILECHANGE" | sed 's_'$CURPATH'/__'`
bash $TO_EXEC $1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment