Table of Contents
The default prompt in Elixir’s IEx
is pretty simple:
iex(1)> IO.puts("Hello, World!")
Hello, World!
:ok
iex(2)>
Since I write a lot of tutorials that require me to paste IEx
output, I’d prefer that the parentheses and counter weren’t there. I just want a simple iex>
on every line, like this:
iex> IO.puts("Hello, World!")
Hello, World!
:ok
iex>
How to change the prompt in IEx
You can configure the prompt by using the IEx.configure/1
function and modifying the :default_prompt
and :alive_prompt
options. Let’s take a look at the default configuration with IEx.configuration/0
:
iex(2)> IEx.configuration()
[
default_prompt: "%prefix(%counter)>",
colors: [],
alive_prompt: "%prefix(%node)%counter>",
inspect: [pretty: true],
history_size: 20
]
Let’s change the prompts to be just "%prefix>"
:
iex(3)> IEx.configure(default_prompt: "%prefix>", alive_prompt: "%prefix>")
:ok
iex>
The prompt has immediately changed to iex>
, great!
How to persist IEx
configuration changes to new sessions
If I restart IEx
after applying the changes above, the prompt is right back to its default:
$ iex
Erlang/OTP 21 [erts-10.1.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]
Interactive Elixir (1.7.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>
To persist the changes, I need to add this configuration line to the local ./.iex.exs
or the global ~/.iex.exs
:
# ~/.iex.exs
IEx.configure(default_prompt: "%prefix>", alive_prompt: "%prefix>")
The ~/.iex.exs
function is run every time IEx
starts. If I restart IEx
now, my configuration is applied at startup:
$ iex
Erlang/OTP 21 [erts-10.1.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]
Interactive Elixir (1.7.4) - press Ctrl+C to exit (type h() ENTER for help)
iex>
Nice! 👍