# Can I "reset" my REPL?

**URL:** https://discuss.ocaml.org/t/can-i-reset-my-repl/11244
**Category:** Learning
**Created:** [January 24, 2023, 8:01pm UTC](https://discuss.ocaml.org/t/can-i-reset-my-repl/11244 "2023-01-24T20:01:36Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![benjamin-thomas](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/benjamin-thomas/32/3966_2.png) [@benjamin-thomas](https://discuss.ocaml.org/u/benjamin-thomas)
#### Post date: [January 25, 2023, 6:33am UTC](https://discuss.ocaml.org/t/can-i-reset-my-repl/11244/3 "2023-01-25T06:33:25Z")

</div>

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: `vim->merlin->ocaml`.

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

```auto
$ cat ./.ocamlinit 
#use "down.top";;
#load "./hello.cmo";;

```

**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.

```auto
$ 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

```auto
$ cat ./ocaml.exec 
#!/bin/bash

echo $$ >./.ocaml.pid
exec ocaml

```

**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.

```auto
while true;do ./ocaml.exec;sleep 0.1;done

```

* * *

It’s ok…ish

I still have a couple of problems:

1. I get garbled output if I try to launch step 3b via a script (via another wrapper), not sure why.
2. `down` won’t save history on receiving a kill signal

Regarding that last point, I’m not sure where `at_exit` is defined

> <https://github.com/dbuenzli/down/blob/09b1cedda9a372fc37d95c7642e8567157717753/src/down.ml#L1015>

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 `up` then `enter`, after REPL reload (triggered itself by a file change). Tmux is handy for that, I could use something like this:

```auto
tmux send-keys -t "PROJ_NAME:PANE_NUM_WITH_REPL" Up
tmux send-keys -t "PROJ_NAME:PANE_NUM_WITH_REPL" Enter

```

---

_[View the full topic](https://discuss.ocaml.org/t/can-i-reset-my-repl/11244)._
