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.
- In gnome-terminal (or the like), Alt+E, A. This is to Select All.
- If you're in ssh, open a different terminal on your local machine.
- 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()