Python Forum
Cutting and Pasting from terminal programs
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cutting and Pasting from terminal programs

I am doing most of my python scripting these days using kaa edit. I ssh to the box I run my server on and run kaa and get hacking.

Works great, however, being a newbie at python, I often have questions. I would love to be able to cut/copy and paste from kaa to a web browser, but the cut buffer for kaa (or for nano, for another example) seems to only live inside the program. Even if I use my mouse on selected text, whatever I copy is not able to be pasted anywhere outside the program.

Surely someone smart has figured this kind of thing out. The way that I currently do it is to scp the whole script back to the local computer, then open it up in a gui text!
It may depend on your system and your terminal. On mine I can use Ctrl-Shift-C and Ctrl-Shift-V to copy and paste in a terminal or in an editor that runs in the terminal such as Jed or nano for example.

Thanks for the reply! Yes, on a local machine terminal ctrl + shift + c or v is how to copy and paste (I'm using a Debian fork). My question above is about how to copy from the terminal session of a remote host and then be able to paste into a web browser on the local host. To do this, you need to get the copy buffer from the remote terminal pumped into the GNU copy buffer of the local computer.

I like to use kaa edit for Python editing, which is a terminal based program that works like a fancy version of nano or edit (or whatever the Windows basic terminal editor is called...been a long time).

Anyway, trawling the web, I patched together a workaround that works on Debian systems:

Requires xsel to be installed and your X11 to be forwarded.

1. First, forward your X11 display to the remote server: ssh -X [email protected]
2. Start a screen session: screen -S mysession
3. Open kaa: kaa
4. Enter screen's copy mode: ctrl-a [
5. Place cursor at desired mark and hit spacebar to set mark
6. Highlight the text you want, then hit spacebar to copy
7. Hit alt-z or otherwise close kaa
8. Use command: cat|xsel -bi or cat|xsel --clipboard
9. Use ctrl-a ] to paste into the STDIN buffer
10. Hit enter, then ctrl-d

Now what you copied is in your GNU copy buffer on the local computer -- Paste away! It seems like a lot of steps, but once you do it a couple of times, it's super straightforward.

-- Matt

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020