Sunday, October 20, 2013

How I left the output redirection to file.

If you feel with linux command line at home, there is often a situation you pipe command outputs. These enable us doing amazing things.

However there are times, when console is not the right place to examine the final output and your favourite editor could do much better job.
In the past I used to output to file and open afterwards, until,... I've noticed it's possible to pipe directly to editor.

Let's assume we're interested in reading tail output in our editor of choice.

Gedit

As my default editor used to be Gedit for quite some time, let's see it in action:
tail -f some.log | gedit
No surprise :), I guess. No extra arguments. Nice!

Morever gedit even provides me with the indicatior (displayed on the tab), that loading is in progress and automatically refreshes contents.

Gvim

I'm in process of transition to gvim usage. I've heard about it's power, never really had a chance to dive deep there. However after watching some vimcasts and reading couple reviews, I'm quite amazed. I'm still trying to memorize the keys for specific tasks (that should be just a question of time and frequency of usage of particular ones).

I made it already my primary editor (wherever I used to use Gedit before).

OK, let's see it in action:
tail -f some.log | gvim -R -
please note -R is not mandatory, but useful, as it indicates file beeing read only.

Kate

I'm not really a KDE guy (these days/years :), but this might be be still be useful for those using kate editor:
tail -f some.log | kate -i 

Bash integration

In the comments of the sites (commandlinefu), where I've found the solution for gvim was one more usecase that caught my attention. Having in the .bashrc following:
function gv() {
  $@ | gvim -R -
}
Enables me doing:
gv tail -f some.log
what makes things even more comfortable. Sure you could replace the function name, as well as the editor with the ones you prefer.

Well, that's it, enjoy (or forget it if you find it useless :) or if interested, share how you achieve it with your editor of choice.

No comments: