ferd / erlang-history

Hacks to add shell history to Erlang's shell
493 stars 30 forks source link

Consider namespacing logs #32

Open michalmuskala opened 7 years ago

michalmuskala commented 7 years ago

Currently, all logs are stored together. That's completely fine, but it becomes problematic when using multiple different repls - erl, iex and lfe since all history is stored together. So now I can "scroll up" elixir commands in lfe or erlang - this is not desirable.

Both lfe and iex achieve the custom repl by passing the -user argument to erl executable. This argument can be obtained using init:get_argument(user) - I'm not sure if there exists a more internal API exposing an already parsed value.

I propose to store logs in ~/.erlang-hostory/<user>/ directory, where <user> is the value of the init argument. As far as I understand the code, this will allow separating the Erlang, Elixir and LFE shell history rather easily.

ferd commented 7 years ago

The PR I have in OTP https://github.com/erlang/otp/pull/1420 lets you configure the path for logs through a kernel env var (the paths are also moved to ~/.cache/ by default). Would this mechanism make sense for you here?

michalmuskala commented 7 years ago

Yes, I think it would be possible for iex to automatically configure this, though it might be hard to do this reliably in a cross-platform way. On the erlang side the use of filename:basedir/2 makes it quite easy, but both iex and lfe are simple bash/batch scripts, so they don't have access to this.

Maybe a way to pass a path relative to the default one would be a solution?

ferd commented 7 years ago

I was more thinking of having their bash script add an item like -kernel shell_history_path ~/.cache/iex-history/ so they segment themselves on their own.

michalmuskala commented 7 years ago

It's not as simple - filename:basedir uses ~/.cache only on Linux. On macOS it will use ~/Library/Caches, etc - on each platform according to the platform's conventions.

ferd commented 7 years ago

yeah but they can just put it into ~/.erlang-history like this library currently does, but with their own prefix. The path is configurable, I don't really have to worry what it is configured to if you don't want the default?

josevalim commented 7 years ago

It is worth pointing out that you can have the same shell running multiple languages. Just press Ctrl+G and start a new session in whatever language you like. So I would say this needs to be configurable per session, much like the expand_fun option is configured per session directly via io:setopts. However I am not sure if this is a possibility.

ferd commented 7 years ago

There is no way to do such thing since there is no context to pass around for it nor is there any way to identify a session.