Created
March 21, 2022 22:34
-
-
Save jc00ke/03074297ac325bfd45e7ed80c862982b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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