views:

5488

answers:

6

Heyas

So I'm trying to move away from using the mouse as much as I can (just a pet project). I know that in the terminal you can do c-k to cut a line and c-u to paste that line back into that same terminal, but I'm looking for something where I can copy a line in the terminal into gnomes clipboard so I can paste it into say a browser or somesuch.

I know that if I use the mouse to highlight text, I can then hit shift-insert to paste that text, which is great, but now I just want to be able to do it without the mouse. Something like c-space highlighting in emacs (but even that doesn't copy into the gnome clipboard).

Thanks

Some more clarification, I have several different terminals open, and on many I've ssh'ed into various remote machines where utilities like xclip/xsel aren't as helpful.

+2  A: 

Stated here, the default commands for GNOME copy and paste are CTRL-SHIFT-C and CTRL-SHIFT-C.

Edit: I found a useful blog post that allows you to enable terminal copy/paste to CTRL-C and CTRL-V in GNOME.

Cory Walker
c-shift-c doesnt work as you still have to use the mouse to highlight the text and remapping anything to ctrl-c is totally unacceptable since ctrl-c is keyboard interupt
Silfheed
A: 

Might I suggest RatPoison as your window manager? As the name suggests, you don't need a mouse at all. I'm not sure how it handles the clipboard though, as I've only ever used it for fun. It may depend on what terminal program you're using.

rmeador
+4  A: 

For interaction with the X11 clipboard from the command line, see this question.


Maybe a side track to what you ask for, but for terminal window interaction I can recommend screen, where you use keys to copy and paste (from a searchable scrollback buffer!). The copy and paste operation only is between screen controlled windows though like you describe with the terminal window and c-u & c-k, but you can easily dump to /tmp/screen-xchange and then use xclip to copy to the X11 clipboard.

hlovdal
hey, xclip is very cool and geting closer, but still a ways off since it only works on my local machine. I have several terminals sshd to different machines at the same time and I'm simply trying to copy whatever text that is in the terminal to the gnome clipboard with the keyboard. Cool find tho, thanks
Silfheed
You can run your ssh sessions all inside screen, and even open the same screen session in multiple terminals. I do this all the time... then you just ^A[...^M to select in one window, and ^A] to paste in another.
ephemient
+1  A: 

For long time I was also trying to sort out it, using vt100.translations:

!! from http://www.fifi.org/doc/xterm/xterm.faq.html#future_work "XTerm*vt100.translations: #override \n\ Insert: string(\001) \n\ Shift Up: scroll-back(1,lines) \n\ Shift Down: scroll-forw(1,lines) \n\ Shift Right: string(0x1b) string("f") \n\ Shift Left: string(0x1b) string("b") \n\ Shift Delete: string(0x1b) string(0x08) \n\ Shift Tab: string(0x1b) string("*") \n\ 0x1000FF0D: scroll-back(1,page) \n\ 0x1000FF0E: scroll-forw(1,page) \n\ 0x1000FF09: string(\010) \n\ 0x1000FF0A: string(\005) \n\ BackSpace: string(0xff) \n\ Select: select-start() \n\ : select-extend() \n\ 0x1000FF02: select-end(PRIMARY,CUT_BUFFER0) \n\ Meta 0x1000FF02: select-end(CLIPBOARD) \n\ 0x1000FF04: insert-selection(PRIMARY,CUT_BUFFER0) \n\ Meta 0x1000FF04: insert-selection(CLIPBOARD) \n\ F1: string(0x1b) string("OP")

no success

OK if we have set some key for select-start select-end ..extend but how to bring cursor their.

gnu screen may be solution but, it will not properly in zsh, and we can not bring cut text in Xclipboard.

A: 

I know if your shell program is bash or tcsh, it uses readline library to do line editing, so the Control-K function is handled by readline and is stored in a "kill-ring" buffer inside your shell program. It is impossible to steal the contents of the kill-ring from your shell (unless your shell has specific functionality programmed into it that allow it), however you can re-configure the Control-K to perform some other action by configuring the .inputrc file in your home directory. So you could configure it to perform a macro, for example, outputting the text "xclip -in\n" and then dumping the contents of the kill-ring to the output along with a "Control-D" action to terminate the text. This is mostly all explained in the readline manpage.

I've never tried anything like it before so I don't know if that would work or not, but that's the route I would try first.

Ramin Honary
A: 

This is a super-clunky hack, but it works for copying the last line of output from the last run command in a terminal using only the keyboard (and a python script), and it can work over ssh.

Here's how you use it.

  1. In gnome-terminal (or the like), Alt+E, A. This is to Select All.
  2. If you're in ssh, open a different terminal on your local machine.
  3. Run the attached script, which i call lastline on my machine.

Then you've got one line of text with no newline on your gtk clipboard. The script works by using the x selection clipboard from selecting all the terminal's text and putting the third-to-last line of it on the gtk clipboard. This script can be modified to select different parts of the x selection, which would correspond to different parts of the terminal's text buffer. However, it's still a long ways from an interactive cursor :(

It'd be great if gnome-terminal integrated keyboard-driven selection support.

This example puts "/usr/bin/gcc" on the gtk clipboard (remember to Select All before running lastline):

$ which gcc
/usr/bin/gcc
$ lastline

Here's the script i call lastline:

#!/usr/bin/env python

import sys, subprocess
import optparse
__version__ = "0.1"

def main():
    try:
        process = subprocess.Popen(["xsel"], stdout=subprocess.PIPE)
    except OSError:
        sys.exit("you must install xsel")
    (stdout, _) = process.communicate()

    lines = stdout.split("\n")
    if len(lines) < 3:
        text = ""
    else:
        text = lines[-3]

    import gtk
    clipboard = gtk.clipboard_get()
    clipboard.set_text(text)
    clipboard.store()

if __name__ == "__main__":
    parser = optparse.OptionParser(version=__version__)
    (options, args) = parser.parse_args()
    main()
thejoshwolfe