问题描述
我刚开始使用Elixir,并且一直使用 iex
shell。我可以将会话保存/记录到文件吗?
I just started working with Elixir and have been using the iex
shell quite a bit. Is it possible for me to save / log a "session" to a file?
谢谢。
推荐答案
在Erlang / OTP-20及更高版本中
In Erlang/OTP-20 and higher
-
似乎将历史记录写入文件的过程是异步进行的,并且在关闭IEx Shell之前,需要一些时间来完成此操作。您需要稍等片刻才能退出外壳程序(例如,按< ctrl + \>
)。
It seems that the process that is writing the history to the file does it asynchronously and it needs some time to do it before the IEx shell is closed. You need to wait a bit before you exit the shell (e.g. press <ctrl+\>
).
我找到了两种方法。
支持的历史记录是通过
键盘上的向上/向下箭头可获得的历史记录。
The history supported is the one available through up/down arrows on the keyboard.
安装在Ubuntu Linux中:
Installation in Ubuntu Linux:
sudo su
cd /usr/local/src
git clone https://github.com/ferd/erlang-history.git
cd erlang-history
make install
现在每个现在启动的基于Erlang的REPL(即IEx)都应使用 erlang-history
。
Now every now started Erlang based REPL (and that is IEx) should use erlang-history
.
您也可以尝试更为通用的REPL增强程序/修复程序,它是 readline包装器:
As an alternative you can try a more generic REPL enhancer/fixer rlwrap which is a "readline wrapper":
rlwrap -a -A iex -S mix
(如果您使用的是Ubuntu Linux,请使用: sudo apt-get install rlwrap
)
(In case you are on Ubuntu Linux use: sudo apt-get install rlwrap
)
它让您向REPL添加了更多功能,例如pipeto过滤器 rlwrap -a -z pipeto iex
,使您可以将内容通过管道传递到Shell命令-对于阅读文档非常有用,例如: iex> h流|更少
()
It let's you add a lot more features to the REPL like e.g. the pipeto filter rlwrap -a -z pipeto iex
that lets you pipe things to shell commands - very useful to read documentation i.e.: iex> h Stream | less
(more)
了解缺点:
- 它会破坏代码完成(即制表符Ili
为什么这是非常有用的功能-命令历史-尚未包括在Elixir / Erlang中吗?
Why is this very useful feature - command history - not already included in Elixir/Erlang?
- https://github.com/elixir-lang/elixir/issues/2945#issuecomment-66594851
- https://github.com/elixir-lang/elixir/issues/1516#issuecomment-21772851
在使用参见。
这篇关于如何保存/记录iex shell的输出以获得持久的命令历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!