Skip to content

Instantly share code, notes, and snippets.

@jc00ke
Created March 21, 2022 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jc00ke/03074297ac325bfd45e7ed80c862982b to your computer and use it in GitHub Desktop.
Save jc00ke/03074297ac325bfd45e7ed80c862982b to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# https://discourse.elm-lang.org/t/simple-watcher-for-elm-make/3694
# https://twitter.com/evancz/status/1131650856024125440
# nice colors
COLOR_OFF="\e[0m";
DIM="\e[2m";
# random filename for the lock; see below
LOCKNAME=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 16);
function run {
(
flock 200; # don't let multiple `elm make` scripts run at once.
# reset the terminal scrollback history
# --> all the errors you see are the current ones, not stale
clear;
tput reset;
echo -en "${DIM}";
date -R;
echo -en "${COLOR_OFF}";
elm make src/Main.elm --output /dev/null
# on Linux optionally prepend for better performance: sysconfcpus -n 1
) 200>"/var/lock/${LOCKNAME}"
}
# run the compiler when running the script...
run;
# ... and when you save files in these directories
inotifywait -mqr -e close_write --format '%w %e %f' ./src | while read DIR EVENT FILE; do
run;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment