如何保存/记录iex shell的输出以获得持久的命令历史记录? [英] How to save/log the output of the iex shell to get persistent command history?

查看:93
本文介绍了如何保存/记录iex shell的输出以获得持久的命令历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用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


自Erlang / OTP-20rc2起,Shell历史记录为通过端口此库的端口开箱即用(虽然默认情况下默认为禁用) Erlang / OTP代码库。通过将 shell_history 内核环境变量设置为启用,并启用 export ERL_AFLAGS =-kernel shell_history enabled 添加到您的环境变量中(请参阅配置选项以了解更多信息选项)。

Since Erlang/OTP-20rc2, Shell history is supported out of the box (although initially disabled by default) through a port of this library to the Erlang/OTP code base. Enable the shell in these versions by setting the shell_history kernel environment variable to enabled with export ERL_AFLAGS="-kernel shell_history enabled" added to your environment variables (see Configuration Options to see more options).

- https://github.com/ferd/erlang-history

似乎将历史记录写入文件的过程是异步进行的,并且在关闭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+\>).

我找到了两种方法。


erlang-history(eh)是一对很小的文件,可用于修补Erlang-OTP系统,以在Erlang
shell中添加对历史的支持。

erlang-history (eh) is a tiny pair of files that can be used to patch an Erlang-OTP system to add support for history in the Erlang shell.

支持的历史记录是通过
键盘上的向上/向下箭头可获得的历史记录。

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增强程序/修复程序 rlwrap ,它是 readline包装器:

As an alternative you can try a more generic REPL enhancer/fixer rlwrap which is a "readline wrapper":


...一个小实用程序,它使用GNU readline库来允许
编辑任何命令的键盘输入。

...a small utility that uses the GNU readline library to allow the editing of keyboard input for any command.



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

在使用 asdf 参见

这篇关于如何保存/记录iex shell的输出以获得持久的命令历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆