Thanks @Chet_Murthy, you put me on the right track!
I got initially confused after a bit of fiddling and, mainly, I could not see a way to kill the ocaml REPL without relying on its name. That would be too coarse as I would also kill other processes, such as the one launched by:
Here’s what I got so far:
Step 1) Prepare a local
.ocamlinit file for customization on REPL start.
Down looks appropriate for a minimal setup with readline functionality
$ cat ./.ocamlinit
Step 2) Launch watchers with:
foreman start -f Procfile.dev
Foreman is just a handy tool, launching those watchers via other terminal panes would also work.
$ cat ./Procfile.dev
compile: find *.ml | entr -p ocamlc /_
kill_repl: find *.cmo | entr -p bash -c 'kill $(cat ./.ocaml.pid)'
Step 3a) Use a wrapper script to track the REPL PID
$ cat ./ocaml.exec
echo $$ >./.ocaml.pid
Step 3b) Launch the wrapper in a loop, within the current shell
Here, I sleep in order to be able to
ctrl-d, ctrl-c out of this loop.
while true;do ./ocaml.exec;sleep 0.1;done
I still have a couple of problems:
- I get garbled output if I try to launch step 3b via a script (via another wrapper), not sure why.
down won’t save history on receiving a kill signal
Regarding that last point, I’m not sure where
at_exit is defined
I tried to play with sending different signals, but history did not save so I presume down relies on receiving ctrl+d to trigger
at_exit. Is this correct if you don’t mind me asking @dbuenzli?
Once I got that sorted, the next step is to simulate pressing
enter, after REPL reload (triggered itself by a file change). Tmux is handy for that, I could use something like this:
tmux send-keys -t "PROJ_NAME:PANE_NUM_WITH_REPL" Up
tmux send-keys -t "PROJ_NAME:PANE_NUM_WITH_REPL" Enter