Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference stdout (i.e. output of previous command) quickly in bash?

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

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?

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

like image 916
user1516425 Avatar asked Jul 11 '12 02:07

user1516425


1 Answers

I use backticks with history reference:

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

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

$ e `!!`

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

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.

like image 177
fork0 Avatar answered Nov 09 '22 01:11

fork0