# Simple watcher for \`elm make\`

**URL:** <https://discourse.elm-lang.org/t/simple-watcher-for-elm-make/3694>\
**Category:** Show and Tell\
**Created:** [May 24, 2019, 7:00pm UTC](https://discourse.elm-lang.org/t/simple-watcher-for-elm-make/3694 "2019-05-24T19:00:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janiczek](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/janiczek/32/4516_2.png) [@Janiczek](https://discourse.elm-lang.org/u/Janiczek)\
**Post date:** [May 24, 2019, 7:00pm UTC](https://discourse.elm-lang.org/t/simple-watcher-for-elm-make/3694/1 "2019-05-24T19:00:23Z")

</div>

Given [some context](https://twitter.com/czaplic/status/1131650856024125440) (me complaining about not being able to use incremental builds with 0.19 and Evan telling me how to hotfix it for now) **I want to share my setup for an `elm make` watcher** that I use for development of our Elm app.

```bash
#!/usr/bin/env bash

# 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;

```

I then have my tmux windows like this: vim on the left, errors on the right.

 ![errors](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/2X/6/62c8d6a1c54878de2ceabe755c55e984f560954f.png)

It’s a bit minimalistic but serves me well.

So, the base of it is essentially an `inotifywait ... | while ...; do elm make ...; done` but there are some bells and whistles: resetting the terminal scrollback history, making sure we only run `elm make` once to not trigger the `not enough bytes` 0.19 compiler crash, etc.

Hope it is of some use to somebody!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [June 3, 2019, 7:09pm UTC](https://discourse.elm-lang.org/t/simple-watcher-for-elm-make/3694/2 "2019-06-03T19:09:42Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
