diff options
author | Jonas Smedegaard <dr@jones.dk> | 2014-04-28 14:58:50 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2014-04-28 14:58:50 +0200 |
commit | 8268aad16e5b7b2f9b03bd4e358edc24b2d999a1 (patch) | |
tree | 6ab1820f1b36120f8e82b9509929ed7e56b4082d | |
parent | 6599236325b1db3d57bb0428fd97affa4caaaf0e (diff) |
Rewrite using entr and getopt.
-rwxr-xr-x | localikiwatchstyling | 57 |
1 files changed, 49 insertions, 8 deletions
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 <dr@jones.dk> # -# 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 <<EOF +Usage: $PRG [-v|--verbose] + +Execute at the root of an Ikiwiki project to watch styling folder +and regenerate with debug hints applied when main SCSS file changes. +EOF +} + +exit1() { + echo >&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" |