[SLUG] [PIG] Sharing screen's paste buffer with X11's selection buffer

From: Dylan William Hardison (dylan@hardison.net)
Date: Sat Oct 07 2006 - 03:08:49 EDT


(If you don't know what gnu screen [1] is, this post will not make much
sense. Even so, if you use the terminal at all, screen is quite useful!)

One very nifty feature of screen is being able to copy and paste without
a mouse. One not so nifty feature is that this doesn't integrate with
X11's own selection mechanism.

Of course, if you have X11, you can just use the mouse to copy and
paste, right? Right. But what if you don't want to use the mouse? Well,
then, tough monkeys.

I've been using a mouseless desktop lately (thanks to ion3 [2], conkeror
[3], and my usual (large) collection of ncurses applications.

In conkeror, I can press 'c' to get the content of the address bar in
X's clipboard. I can paste this into irssi (or any other terminal
program) with shift-insert.

But, if I want to follow a link in my irssi session, I cannot copy this
without using the mouse, unless I use screen. And even if I use screen,
I can't paste this into conkeror at all, because it's private to
screen's own buffer.

So, the problem is: How to get screen to share its paste buffer with X?
The answer is a very interesting hack.

Step 1) Screen has two commands of interest: readbuf and writebuf.
readbuf reads in the content of a file to the screen paste buffer, and
writebuf writes the contents of that buffer to a file.

Step 2) There is a program called xclip (with a debian package of the
same name). 'xclip -i' takes standard in, and puts it in the X selection
buffer. 'xclip -o' writes the contents of the X selection buffer to
standard out.

Step 3) the command 'screen -X' allows one to run screen commands from a
script.

The result is a shell script called 'sclip' [4]
and the following three lines to ~/.screenrc:

bind < exec sclip load
bind > exec sclip dump
bind v exec sclip paste

And now I have one less reason to use the mouse.

[1] http://www.gnu.org/software/screen/
[2] http://modeemi.cs.tut.fi/~tuomov/ion/
[3] http://conkeror.mozdev.org/
[4] http://hardison.net/sclip (or see below)

#!/bin/sh
FILE=$TEMPDIR/sclip
ACTION=${1:-"blaa"}

if [ $TERM != 'screen' ]; then
                exit 1
fi

case $ACTION in
        paste)
                screen -X eval "readbuf $FILE" 'paste .'
        ;;
        load)
                xclip -o > $FILE
                screen -X readbuf $FILE
        ;;
        dump)
                screen -X writebuf $FILE
                xclip -i < $FILE
        ;;
esac

-- 
Thus spake the master programmer:
        "After three days without programming, life becomes meaningless."
              -- Geoffrey James, "The Tao of Programming"
-
GPG Fingerprint: E3CD FDAB 82C4 14FD 7B57  430B 770E 0EAF FB53 12C2
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 17:50:53 EDT