elixir-lang/elixir

Persistent command history

Closed this issue · 5 comments

(Intermediate IEx Feature Request)

It would be convenient if your IEx command history could persist across sessions.

I'm suggesting this issue be tagged as Level:Intermediate because aside from modifying the IEx.History module to be its own process, you'd have to process navigating the history with the up/down arrow keys through the new IEx.History process. That would mean customizing the erlang C driver used by IEx here, or moving to ncurses or something. That kind of thing out of my domain expertise.

For those of you familiar with Ruby's pry gem, I think it would be excellent if we could bring that sort of feature-rich, high-level functionality to Elixir's standard REPL. Having a persistent command line history is a good place to start.

Pry implements this with a ~/.pry-history file. Every statement from every pry session appends to this file. It's a little inconsistent, due to the limitations of the implementation. From my observations, new sessions load in the .pry-history as a personal history, then when executing a command, a) append to their personal history and b) append to the .pry-history.

This results in new sessions being able to see a shared history on load, but only their personal one after start. Commands issued in sessions do not update histories of other live sessions because of this ownership.

As far as I can tell, the correct approach here that avoids pry's shortcomings would be to make IEx.History a singleton actor that is found or initialized when an IEx.Server starts (changing the initialization process). Servers would send :append messages to this singleton (changing the update_history function).

Other related tasks outside of the rewrite of IEx.History and modifying the tty driver include updating the history helpers.

@christhekeele Thanks, a couple notes:

  1. This is not a straight-forward task because modifying the tty driver requires patching and carrying our own copy of the tty driver. For example, this project adds this feature to the VM overall. This per-se is a no-go.
  2. I don't think it should be a singleton. For example, when connecting to remote notes, you probably want to keep a history per remote node.

Today, you can use rlwrap and others to get this feature today, in general I don't think it is worthy to add those as extra extra dependencies to Elixir. The long term goal is to add this feature to Erlang.

In any case, please use the elixir-core mailing list for discussions on new features. We mostly don't accept feature requests in the issues tracker. :) Thanks!

I had to come across this issiue dozen of times to notice the reference of rlwrap. It solves the situation.

#rlwrap But the downside of it is that it braks tab (code) completion of IEx. That's why I have found better to use erlang-history - find out more here: http://stackoverflow.com/a/28514369/408011.