diff --git a/run.sh b/run.sh index faba8f1..e2a3680 100755 --- a/run.sh +++ b/run.sh @@ -3,7 +3,7 @@ # Run jekyll site at http://127.0.0.1:4000 # # Requirement: -# fswatch › http://emcrisostomo.github.io/fswatch/ +# Option '-r, --realtime' needs fswatch › http://emcrisostomo.github.io/fswatch/ # # © 2019 Cotes Chung # Published under MIT License @@ -14,6 +14,7 @@ CONTAINER=.container SYNC_TOOL=_scripts/sh/sync_monitor.sh cmd="bundle exec jekyll s" +realtime=false help() { echo "Usage:" @@ -26,7 +27,7 @@ help() { echo " -b, --baseurl The site relative url that start with slash, e.g. '/project'" echo " -h, --help Print the help information" echo " -t, --trace Show the full backtrace when an error occurs" - + echo " -r, --realtime Make the modified content updated in real time" } @@ -61,12 +62,24 @@ check_unset() { } +check_command() { + if [[ -z $(command -v $1) ]]; then + echo "Error: command '$1' not found !" + echo "Hint: Get '$1' on <$2>" + exit 1 + fi +} + + main() { init cd $CONTAINER python _scripts/py/init_all.py - fswatch -0 -e "\\$CONTAINER" -e "\.git" ${WORK_DIR} | xargs -0 -I {} bash ./${SYNC_TOOL} {} $WORK_DIR . & + + if [[ $realtime = true ]]; then + fswatch -0 -e "\\$CONTAINER" -e "\.git" ${WORK_DIR} | xargs -0 -I {} bash ./${SYNC_TOOL} {} $WORK_DIR . & + fi echo "\$ $cmd" eval $cmd @@ -105,6 +118,11 @@ do cmd+=" -t" shift ;; + -r|--realtime) + check_command fswatch 'http://emcrisostomo.github.io/fswatch/' + realtime=true + shift + ;; -h|--help) help exit 0