Improved? IEx shell history. My pet project/hack session

Hi,

I wrote an initial version of this a month or 2 ago. I recently improved on it after I crashed my IEx shell at work.

Features:

1 Persist history
2 Persist the shell variable bindings (that get reloaded when you restart)
2 List history
3 Search history
4 Re-execute a command in history
5. Scoping rules
6. Update configuration

I probably broke some rules on how it was implemented, but it works for me. Feel free to play with it…Next on my list is to make it play better with the current IEx history.

Pics attached
Screen Shot 2021-09-01 at 3.48.12 PM
Screen Shot 2021-09-01 at 3.51.45 PM
Screen Shot 2021-09-01 at 3.55.48 PM
Screen Shot 2021-09-01 at 3.52.28 PM
Screen Shot 2021-09-01 at 3.53.04 PM

Display history

9 Likes

Added a few improvements:

  1. Can set the max width when displaying output
  2. Copy/pasting now works
  3. If an operation in not correctly evaluated you have the option to not save it
2 Likes

Love a nice bit of code hacking.

Are you aware that you can do the following (in my case in .bashrc) and it will persist history?
export ERL_AFLAGS="-kernel shell_history enabled"

Between that and the normal readline shortcuts like ctrl+r I think most of what you’re looking for is built-in.

OTOH, if you’re building it for fun - nice work!

2 Likes

Thanks,

The problem withe ctrl+r is that it’s a line history, not a command history. So if, for example, you paste a large list, map or struct into the shell it renders it useless. I use the kernel flags too, but that’s a globally shared view which is fine in some cases, but not always (I also don’t think it includes date etc…plus I haven’t found a nice way to just show the history.

Still, as you said … it’s all for fun

3 Likes

OK, latest version:

In addition to saving history and bindings, this version adds:

  1. Supports for aliasing the History module

  2. Copy/paste a command from history to the shell (so you can edit it)

  3. Use ctrl+u and ctrl+k to move up and down history. Unlike the standard history search with the arrow keys this is command not line based. So, for example:

Paste:

iex(1)> config = [
...(1)>   scope: :local,
...(1)>   history_limit: :infinity,
...(1)>   hide_history_commands: true,
...(1)>   prepend_identifiers: true,
...(1)>   key_buffer_history: true,
...(1)>   command_display_width: :int,
...(1)>   save_invalid_results: false,
...(1)>   show_date: true,
...(1)>   save_bindings: true,
...(1)>   colors: [
...(1)>     index: :red,
...(1)>     date: :green,
...(1)>     command: :yellow,
...(1)>     label: :red,
...(1)>     variable: :green
...(1)>   ]
...(1)> ]
[
  scope: :local,
  history_limit: :infinity,
  hide_history_commands: true,
  prepend_identifiers: true,
  key_buffer_history: true,
  command_display_width: :int,
  save_invalid_results: false,
  show_date: true,
  save_bindings: true,
  colors: [
    index: :red,
    date: :green,
    command: :yellow,
    label: :red,
    variable: :green
  ]
]

ctrl+u:

iex(2)> config = [ scope: :local, history_limit: :infinity, hide_history_commands: true, prepend_identifiers: true, key_buffer_history: true, command_display_width: :int, save_invalid_results: false, show_date: true, save_bindings: true, colors: [ index: :red, date: :green, command: :yellow, label: :red, variable: :green ]]
3 Likes

OK, fixed a bad bug where it would not work on the latest version of Elixir.

2 Likes