Last active
December 17, 2015 20:39
-
-
Save egobrain/5669317 to your computer and use it in GitHub Desktop.
Script run make in current folder if files of specific type are changed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage() { | |
cat <<EOF | |
usage: $(basename $0) [OPTIONS] | |
This script run make in folder | |
if file of specific type is changed | |
OPTIONS: | |
-h -- show this message | |
-p path -- path to monitor | |
-b build -- build option | |
-e exts -- etensions, e.g. js coffee html | |
EOF | |
} | |
div() { | |
local columns=$(($(tput cols) - 8)) | |
local line=$(printf '%0.1s' "-"{1..500}) | |
printf "\e[01;31m---- 8< ${line:0:${columns}}\e[0m\n" | |
} | |
contains() { | |
local e | |
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done | |
return 1 | |
} | |
# get the current path | |
CURPATH=`pwd` | |
EXTS=('css' 'coffee' 'html') | |
MPATH="." | |
BUILDARG="" | |
while getopts "hp:b:e:" OPTION | |
do | |
case $OPTION in | |
h) | |
usage | |
exit 1 | |
;; | |
p) | |
MPATH=$OPTARG | |
;; | |
b) | |
BUILDARG=$OPTARG | |
;; | |
e) | |
EXTS=$OPTARG | |
;; | |
esac | |
done | |
inotifywait -mqr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -e close_write,modify $MPATH | | |
while read date time dir file; do | |
ext="${file##*.}" | |
if contains $ext ${EXTS[@]}; then | |
FILECHANGE=${dir}${file} | |
# convert absolute path to relative | |
# FILECHANGEREL=`echo "$FILECHANGE" | sed 's_'$CURPATH'/__'` | |
echo "At ${time} on ${date}, file $FILECHANGE was changed. Rebuilding." | |
# Actual command to execute when CSS or JS file is changed | |
div | |
make $BUILDARG | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment