A module to list all IEx history

defmodule History do
  def grep(term) do
    load_history()
    |> Stream.filter(&String.match?(&1, ~r/#{term}/))
    |> Enum.reverse()
    |> Stream.with_index(1)
    |> Enum.each(fn {value, index} ->
      IO.write("#{index}  ")
      IO.write(String.replace(value, term, "#{IO.ANSI.red()}#{term}#{IO.ANSI.default_color()}"))
    end)
  end
  def grep do
    load_history()
    |> Enum.reverse()
    |> Stream.with_index(1)
    |> Enum.each(fn {value, index} ->
      IO.write("#{index}  #{value}")
    end)
  end
  defp load_history, do: :group_history.load() |> Stream.map(&List.to_string/1)
end

I wrote a module that would list IEx history and also search through them just like the bash command history | grep ssh. I use this module in .iex.exs

While working on it, I learned about disk_log and also found a neat erlang module called :group_history in the erlang otp source code.

I would appreciate any feedback to improve the code.

6 Likes