elixir - 如何保存 IEx 历史记录?

标签 elixir elixir-iex

通过 IEx(Elixir 的 REPL),我希望能够保存我的命令历史记录。

例如:

我可以打开一个新的 IEx session 并执行命令。执行命令后,我可以按向上箭头并预先填充我的最后一个命令。关闭 IEx 并重新打开后,我想访问我最后的命令。

有办法做到这一点吗?

最佳答案

对于 Erlang/OTP 20

这是内置的(来自 https://hexdocs.pm/iex/IEx.html#module-shell-history )

From Erlang/OTP 20, it is possible to get shell history by passing some flags that enable it in the VM. This can be done on a per-need basis when starting IEx:

iex --erl "-kernel shell_history enabled"

If you would rather enable it on your system as a whole, you can use the ERL_AFLAGS environment variable and make sure that it is set accordingly on your terminal/shell configuration.

On Linux [and macOS]:

export ERL_AFLAGS="-kernel shell_history enabled"

On Windows:

set ERL_AFLAGS "-kernel shell_history enabled"

要显示历史文件所在的位置,请从 erl 运行以下代码(显示 Mac OS 示例值):

1> filename:basedir(user_cache, "erlang-history")
"/Users/your.username/Library/Caches/erlang-history"

要将文件设置到其他位置,请使用 shell_history_path/path/to/history-file option from the erlang docs (compatible with Elixir/iex) :

export ERL_AFLAGS="-kernel shell_history_path '\"$HOME/.erlang-history\"'"
<小时/>

适用于 Erlang/OTP 19 及以下版本

尝试使用https://github.com/ferd/erlang-history

> git clone https://github.com/ferd/erlang-history.git
> cd erlang-history
> sudo make install    # may not need sudo depending on installation

关于elixir - 如何保存 IEx 历史记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45405070/

相关文章:

mysql - 如何关闭与Mariaex和Elixir的联系

elixir - 如何仅从ecto模型获取字段?

formatting - Iex 中是否有默认启用千位分组(100_000)的开关

elixir - 有没有相当于 Rails Console 的 Phoenix

memory-management - Elixir/Erlang 如何管理函数调用中传递的变量的内存?

heroku - 在 Heroku CI 上缓存

elixir - 如何在 Elixir 的控制台输出中获取行号

elixir - iex- 如何从 app 文件夹外运行 elixir 项目

elixir - Ecto:自定义 binary_id