通过 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/