How do I save IEx history?

Viewed 6739

With IEx (Elixir's REPL), I'd like to be able to save my command history.

For example:

I can open up a new IEx session and execute a command. After executing the command I can press the up arrow and have my last-command pre-populated. After closing IEx and re-opening, I'd like to have access to my last commands.

Is there a way to do this?

4 Answers

I don't know if things changed at some point, but I found the above did not work. After looking at the man page for iex, I noticed that it needed to be

export ELIXIR_ERL_OPTIONS="-kernel shell_history enabled"

(note the additional ELIXIR). Perhaps the original solution was cogent was relevant for erl (I found it worked for that), but iex added the qualifier? Since the original question was for iex though, figured it should be updated.

I'm using the oh-my-zsh, so I put on the vim ~/.zshrc:

# Enable history in IEX through Erlang(OTP)
export ERL_AFLAGS="-kernel shell_history enabled"

then source ~/.zshrc and now always load. Thank's @loeschg.

For docker compose, you will need to create a volume to save the history, and tell Erlang where it is via -kernel shell_history_path. The path needs to be an Erlang term, so make sure it's '"tripple quoted"':

version: '3'

services:
  elixir:
    environment:
      ERL_AFLAGS: -kernel shell_history enabled -kernel shell_history_path '"/somewhere/sensible"'
    volumes:
      - type: volume
        source: shell_history
        target: /somewhere/sensible

volumes:
  shell_history:
Related