summaryrefslogtreecommitdiff
path: root/localikiwatchstyling
blob: 08a4876004689821796c30a6be2ccd94e8c43976 (plain)
  1. #!/bin/sh
  2. #
  3. # /usr/local/bin/localikiwatchstyling
  4. # Copyright 2014 Jonas Smedegaard <dr@jones.dk>
  5. #
  6. # Watch Ikiwiki styling and regenerate with debug hints when it changes
  7. #
  8. # Depends: ruby-compass, entr
  9. # Recommends: libnotify-bin
  10. showhelp() {
  11. cat <<EOF
  12. Usage: $PRG [-v|--verbose]
  13. Execute at the root of an Ikiwiki project to watch styling folder
  14. and regenerate with debug hints applied when main SCSS file changes.
  15. EOF
  16. }
  17. exit1() {
  18. echo >&2 "Error: $1"
  19. echo >&2 "Exiting..."
  20. exit 1
  21. }
  22. PRG=$(basename "$0")
  23. TEMP=$(getopt -s sh -o hv -l help,verbose -n "$PRG" -- "$@")
  24. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  25. eval set -- "$TEMP"
  26. verbose=
  27. while true ; do
  28. case "$1" in
  29. -h|--help) showhelp; exit 0 ;;
  30. -v|--verbose) verbose=x; shift ;;
  31. --) shift ; break ;;
  32. *) echo >&2 "ERROR: Internal error resolving options." ; exit 1 ;;
  33. esac
  34. done
  35. stem=
  36. if [ -f styling/style.scss ]; then
  37. stem=style
  38. elif [ -f styling/local.scss ]; then
  39. stem=local
  40. else
  41. exit1 "Failed to locate style.scss or local.scss in styling dir."
  42. fi
  43. echo styling/$stem.scss \
  44. | entr sh -c "\
  45. set -eu$verbose;\
  46. cd styling;\
  47. {\
  48. cat $stem.scss;\
  49. if grep -Fxq '@import \"compass/typography/vertical_rhythm\";' $stem.scss; then \
  50. echo 'body {@include debug-vertical-alignment;}';\
  51. fi;\
  52. } | scss -s --compass -g $stem.css;\
  53. cp $stem.css ../build/html/$stem.css;\
  54. if [ -n "$DISPLAY" ] && [ -e /usr/bin/notify-send ]; then \
  55. notify-send \
  56. 'Ikiwiki watch' \
  57. 'CSS refreshed from styling/$stem.scss';\
  58. fi"