Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I know this is not how terminals work, but I find myself often wishing there was an easy way of using text (copying it, modifying it, etc) that is already on my terminal window history from some previous command output.

I've imagined it like this:

I'm at my bash shell about to enter a command and I realize I need to type something that is already on the screen a few lines above. I can reach for the mouse and select it, but I hate that. What I really wish at this moment is that my whole terminal became a giant Vim buffer, all of it: the prompts, the commands I've typed, and the output from those commands. Everything. And then I could jump a few lines up, maybe edit a little, and yank some text. Then, return to bash shell mode and paste whatever I yanked into the current command line.

I know there are some options:

  • Naturally, pipe the text I need directly from some command's output to a file, or right to the next command. But for that you have to plan in advance or re-execute the command from your history (supposing the output won't change between invocations).

  • To reach for the mouse and select the text to copy. Lame, annoying, I wish I hadn't to do that, (this isn't the GUI stackexchange site, is it? =)

  • To use my (Mac OS X) Terminal application's "Export text as..." option, and save the terminal text to a file. Then open the file and work with it. Almost, but why go through the step of saving to a file on disk?

So the question is: What do you do in this situation? Is there any trick, tool, shell feature that could be useful in this scenario? Do you just resign yourself to use the mouse or re-type whatever you need to type?

It might be that the problem is that I'm not doing things 'the unix way', but c'mon, this is 2010 and I cannot easily copy some text a few lines away from my cursor?

share|improve this question
1  
add comment

5 Answers

up vote 3 down vote accepted

You could use script (use -f to make sure it flushes every time) and you can have all the output in a file.

Use a terminal multiplexer (screen, tmux etc). For instance, for screen http://web.mit.edu/gnu/doc/html/screen_11.html#

Command: copy Enter copy/scrollback mode. This allows you to copy text from the current window and its history into the paste buffer. In this mode a vi-like full screen editor is active, with controls as outlined below.

Other terminal multiplexers surely have more advanced capabilities.

share|improve this answer
    
Ok. I just learned that a 'Terminal Multiplexer' is probably what I need. Thanks. Also, thanks for the 'script' command hint. –  Sergio Acosta Aug 12 '10 at 10:28
add comment

I use urxvt (rxvt-unicode) and there is a package called urxvt-keyboard-select which may be exactly what you want, if you can install urxvt. The Archlinux package information (that contains pointers) is here:

https://aur.archlinux.org/packages.php?ID=39950

Original source: http://www.github.com/muennich/urxvt-perls

share|improve this answer
add comment

As mentioned here, the Emacs' eshell could be your default term+shell. :) Then you'd use the usual text navigating keys there as a minimum. If you learned more special keys, then the following features of Emacs' eshell can be accessed:

share|improve this answer
add comment

In tmux (a terminal multiplexer) you can press Ctrl+A-[ to switch to the Vi buffer mode where you can navigate around the screen, scroll the buffer back and forth, copy text etc. The default shortcut is actually Ctrl+B-[ but that was obviously meant to be reconfigured. Also, the default buffer mode is Emacs but you can configure it to be Vi.

Check out tmux, it really is a great modern terminal multiplexer. Besides working with buffer you can split screen in multiple windows, connect to the same session from multiple terminals etc. For ultimate convenience you can even make it your login shell if you tell it what your actual shell is.

On OpenBSD tmux was even made part of the base system.

See man page for tmux for more details. Also see screenshots on http://tmux.sourceforge.net/

share|improve this answer
    
tmux is the coolest! –  gabe. Aug 12 '10 at 19:21
    
Thanks. Now using tmux and living in terminal heaven. –  Sergio Acosta Aug 16 '10 at 12:10
    
How is pasting working for you in Vi copy mode? –  zvolkov Aug 16 '10 at 17:22
add comment

In emacs, M-x shell handle edition of previous output. You can easily copy paste previous commands output, or any part of your buffer, like a regular buffer. I am pretty sure there should be a vim equivalent.

share|improve this answer
1  
That is very near to what I want, but I need to be in Emacs or Vim already. +1 –  Sergio Acosta Aug 12 '10 at 10:25
    
Yes, it could be your default term+shell. :) Then you'd use the usual text navigating keys there as a minimum. If you learned more special keys, then the following features of Emacs' eshell can be accessed. –  imz -- Ivan Zakharyaschev Mar 21 '11 at 7:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.