在bash中快速引用标准输出(即上一条命令的输出)? [英] Reference stdout (i.e. output of previous command) quickly in bash?

查看:449
本文介绍了在bash中快速引用标准输出(即上一条命令的输出)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以快速(例如通过键盘快捷键等)引用前一条命令输出到stdout的输出?

Is there a way to quickly (e.g. via a keyboard shortcut, etc.) to reference the output of the previous command's output that it wrote to stdout?

对于例如,如果我这样做:

For example, if I did this:

which rails

,它返回 / usr / local / bin / rails ,然后我想在textmate中打开该文件,我可以-像这样输入:

and it returned /usr/local/bin/rails and then I wanted to open that file in textmate, I could re-type the output like this:

mate /usr/local/bin/rails

但是有没有一种方法可以快速引用输出而不必重新输入?

but is there a way to quickly reference the output without having to re-type it?

注意:我知道我可以做 mate $(哪个轨道),但是我特别希望引用stdout。

NOTE: I am aware I can just do mate $(which rails), but I am specifically looking to reference stdout.

推荐答案

我在历史记录中使用反引号:

I use backticks with history reference:

$ which rails
/usr/local/bin/rails
$ mate `!!`

实际上,我的编辑器(以gvim开头的脚本)的别名为 e ,因此看起来较短:

Actually, my editor (a script starting gvim) is aliased to e, so it looks even shorter:

$ e `!!`

,您始终可以绑定到热键(有关 bind 命令和 readline支持,请参见bash手册页)。

and you can always bind to a hotkey (see bash man page for bind command and readline support).

此外,如果您可以使用剪切缓冲区(在X应用程序中用鼠标选择),则可能会出现如下所示的热键有用:

Also, if you can use cut buffers (select with a mouse in an X application), a hotkey for something like the below might be useful:

$ e $(xclip -out)

该命令将使用命令行剪切缓冲区中的所有内容如上所述启动编辑器。只需双击即可选择许多路径,则可以非常快速地编辑所选路径。

The command will start the editor as above with whatever was in the cut buffer on command line. Given that many paths are selectable with just a double click, a selected path can be edited very quickly.

这篇关于在bash中快速引用标准输出(即上一条命令的输出)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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