#development #elixir #terminal

You might know that you can add a .iex.exs file to your project to have some code executed when you start an IEx session. But did you know that you can also have a global .iex.exs file?

This file is located in your home directory and is executed every time you start an IEx session. This is a great place to add some helper functions or aliases that you use in every project.

Here's an example of a .iex.exs file that I use:

1defmodule IEx.CustomHelpers do
2  def exit do
3    System.halt()
4  end
5end
6
7import IEx.Helpers
8import IEx.CustomHelpers

This file defines a module with a single function that exits the IEx session. It then imports the default IEx.Helpers module and the custom module so that you can use the recompile function in your IEx session.

It also imports the IEx.CustomHelpers module so that you can use the exit function to exit the IEx session.

While you are at it, also define the following environment variable in your shell configuration file (e.g. .bashrc, .zshrc, etc.):

1export ERL_AFLAGS="-kernel shell_history enabled"

This will enable the shell history feature in IEx, which allows you to navigate through the history of commands you've executed in the IEx session using the up and down arrow keys.