From 8268aad16e5b7b2f9b03bd4e358edc24b2d999a1 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Mon, 28 Apr 2014 14:58:50 +0200 Subject: Rewrite using entr and getopt. --- localikiwatchstyling | 57 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) (limited to 'localikiwatchstyling') diff --git a/localikiwatchstyling b/localikiwatchstyling index 9ecb305..08a4876 100755 --- a/localikiwatchstyling +++ b/localikiwatchstyling @@ -3,12 +3,41 @@ # /usr/local/bin/localikiwatchstyling # Copyright 2014 Jonas Smedegaard # -# Watch Ikiwiki styling and regenerate when changing +# Watch Ikiwiki styling and regenerate with debug hints when it changes # -# Depends: ruby-compass, inotify-hookable +# Depends: ruby-compass, entr # Recommends: libnotify-bin -set -e +showhelp() { + cat <&2 "Error: $1" + echo >&2 "Exiting..." + exit 1 +} + +PRG=$(basename "$0") + +TEMP=$(getopt -s sh -o hv -l help,verbose -n "$PRG" -- "$@") +if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi +eval set -- "$TEMP" + +verbose= +while true ; do + case "$1" in + -h|--help) showhelp; exit 0 ;; + -v|--verbose) verbose=x; shift ;; + --) shift ; break ;; + *) echo >&2 "ERROR: Internal error resolving options." ; exit 1 ;; + esac +done stem= if [ -f styling/style.scss ]; then @@ -16,10 +45,22 @@ if [ -f styling/style.scss ]; then elif [ -f styling/local.scss ]; then stem=local else - echo "Couldn't locate either style.scss or local.scss in styling dir." - exit 1 + exit1 "Failed to locate style.scss or local.scss in styling dir." fi -set +e -inotify-hookable -f styling/$stem.scss \ - -c "scss --compass -g styling/$stem.scss:styling/$stem.css && cp styling/$stem.css build/html/$stem.css && if [ -n "$DISPLAY" ] && [ -e /usr/bin/notify-send ]; then notify-send 'CSS updated' 'Ikiwiki $stem.css auto-updated from styling/$stem.scss'; fi" +echo styling/$stem.scss \ + | entr sh -c "\ + set -eu$verbose;\ + cd styling;\ + {\ + cat $stem.scss;\ + if grep -Fxq '@import \"compass/typography/vertical_rhythm\";' $stem.scss; then \ + echo 'body {@include debug-vertical-alignment;}';\ + fi;\ + } | scss -s --compass -g $stem.css;\ + cp $stem.css ../build/html/$stem.css;\ + if [ -n "$DISPLAY" ] && [ -e /usr/bin/notify-send ]; then \ + notify-send \ + 'Ikiwiki watch' \ + 'CSS refreshed from styling/$stem.scss';\ + fi" -- cgit v1.2.3