nhpip

nhpip

IExHistory2 - improved history, save variable bindings from the IEx shell and more...

Hello,

I wrote the initial version of this library as my first Elixir project a couple of years ago, mostly to learn Elixir, but also a desire to be able to save variable bindings between IEx sessions (especially useful when debugging). When the OTP team re-wrote the shell it caused it to break. I’ve been on a recent mission to fix it and update the code.

It’s still very much beta, but folks are more than welcome to play with it.

Here are the key features:

  • Saves IEx shell history between sessions / VM restarts.
  • Saves the shell variable bindings between sessions / VM restarts.
  • Ability to paste (most) terms into the shell without a screen full of garbage (experimental).
  • Navigation keys allow history traversal where multi-line pastes require a single key up/down (instead of up-arrowing every line of whatever was pasted). Unfortunately I had to chose different keys.
  • Shortcut functions permit search, pasting, re-evaluation and editing of items in history.
  • Editing can be done in-situ or in a text editor.
  • Shell variable bindings can be set/get outside of scope of the shell to assist in code debugging.
  • Can be enabled and state shared globally, or on individual shell sessions.

https://hexdocs.pm/iex_history2/IExHistory2.html#content

I really do some dirty hacks to get the bindings and history, it would be awesome if there was an official way to do that.

Most Liked

garazdawi

garazdawi

Erlang Core Team

The best way to get some official support is to open an issue at the Erlang/OTP github and describe what functionality you would like. Maybe we can design something together that would benefit everyone trying to build fancy shell things.

10
Post #2
nhpip

nhpip

The custom parser really helped clean up things. Thanks for the suggestion.

New version available:

garazdawi

garazdawi

Erlang Core Team

If you want to insert yourself between iex_server and group (i.e. the group_leader of iex_server, then you will have to get a hook into iex_server. The good thing here is that the protocol used between iex_server and group is documented so it should be relatively easy to insert something there if the Elixir team wants to allow it.

The protocol inbetween user_drv and group is however not documented and thus we cannot just add something that that snoops inbetween there. What exactly is it that you would like to do there?

In this example it seems like you would like to change the behaviour of the shell evaluator. Maybe it is possible to achieve by using a custom iex parser? If not, then that is yet another place in iex_server to insert yourself in. We don’t allow doing that in Erlang either, but I could see us adding such a feature if it was requested.

ken-kost

ken-kost

Tried it out, great stuff. :+1:
One note, readme reads:

Alternatively the project can be added as a Mix dependancy.

It’s a little confusing because I needed to add it as dependency, otherwise it wouldn’t work, I got:

Erlang/OTP 26 [erts-14.2.1] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.16.0) - press Ctrl+C to exit (type h() ENTER for help)
Error while evaluating: /home/ken/asher/.iex.exs
** (UndefinedFunctionError) function IExHistory2.initialize/0 is undefined (module IExHistory2 is not available)
    IExHistory2.initialize()
    /home/ken/asher/.iex.exs:2: (file)

So readme maybe could read:

Installation

Add :iex_history2 to the list of dependencies in `mix.exs``:

def deps do
  [
    {:iex_history2, "~> 5.1"}
  ]
end

Enable IExHistory2 in .iex.exs:

Code.append_path("~/github/iex_history2/_build/dev/lib/iex_history2/ebin")
IExHistory2.initialize()

I tried to open a PR for this but I get remote: Permission to nhpip/iex_history2.git denied to ken-kost. :disguised_face:

nhpip

nhpip

Hi,

I just updated the code to allow it to be included in mix as part of another application.

Let me know it works now

Thanks

Where Next?

Popular in Libraries Top

OvermindDL1
Been making an MLElixir thing (not released yet…) for fun in spare time in the past day. I’m just trying to see how much I can get an ML...
132 13487 106
New
versilov
Could not wait for the missing Elixir ML libraries to appear, so, I wrote one myself, taking https://github.com/sdwolfz/exlearn as a foun...
New
tmbb
I’ve been working on two packages (not on hex.pm yet) to build admin interfaces for phoenix apps: bureaucrat - which contains a bunch ...
New
mathieuprog
Hello :wave: Allow me to introduce you to Tz, an alternative time zone database support to Tzdata. Why another library? First and fore...
New
asiniy
Hey there! I wrote a download elixir package which does exactly what its name about - an easy way to download files. I saw solutions ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
woylie
I released Doggo, a collection of unstyled Phoenix components. Features Unstyled Phoenix components. Storybook that can be added to...
New
Crowdhailer
I have been updating a library that allows you to pipe between functions that use the erlang result tuple convention. Assuming you have...
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: https://github.com/tmbb/phoenix_ws Phoenix channels are a great...
New
OvermindDL1
I created a new library (rather I pulled out a couple files from my big project), it manages an operating system PID file for the BEAM. ...
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Sub Categories:

We're in Beta

About us Mission Statement