[linux-elitists] fun with xsel

Don Marti dmarti@zgp.org
Fri Jan 17 15:59:47 PST 2003

So how many times has this happened to you?  You're logged into
a remote server reading mail in Mutt and there's an attached file
you want to take a look at.

This issue has been bugging me ever since I rejected a Mutt article
(http://www.linuxjournal.com/article.php?sid=6511) while continuing
to use Mutt.

Usually you can just tell the sender to send you text and be done with
it.  But if you really want to see the attachment you can 

(1) save it and scp it back to your local system

(2) run some X-based viewer on the remote system (painfully slow
over a slow link)

Or, what about just snarfing the attachment into the X secondary
selection, which both ends, assuming you're using ssh with
ForwardX11, magically have access to?  I don't know about you,
but I'm not using the X secondary selection for anything else.

Do this on the remote side:


# a safe temporary file
TEMP=`mktemp /tmp/$LOGNAME.XXXXXXXXXX` || exit 1

# fake up some HTTP headers
echo "HTTP/1.1 200 OK" > $TEMP
echo -n "Content-type: " >> $TEMP
file -bni $1 2> /dev/null >> $TEMP
echo >> $TEMP

# now the actual file
cat $1 >> $TEMP

# uuencode the whole thing and put it in the X "secondary selection"
uuencode $TEMP $TEMP | xsel -s

rm $TEMP

### EOF

and do this on your desktop:



# netcat is a web server if you give it the right headers
# -l -- listen
# -s -- only bind to the lo interface
xsel -o -s | uudecode -o /dev/stdout | \
netcat -l -q 15 -s -p $PORT &> /dev/null &

#substitute your favorite browser
gnome-moz-remote http://localhost:$PORT

### EOF

This second script is a poor substitute for just using protozilla
(protozilla.mozdev.org), but I still haven't gotten protozilla to
install on this Mozilla.  (1.0.0-0.woody.1)

(You will have to do a little Mutt config stuff to make Mutt
recognize the script as the right way to look at attachments.
I called the first script ss, for no reason)

set mailcap_path="~/.mutt-mailcap"

and .mutt-mailcap can be this:

text/*; ss %s
application/*; ss %s
image/*; ss %s
audio/*; ss %s

Don Marti                  Even if we don't get DMCA reform, loudly
http://zgp.org/~dmarti     demanding DMCA reform is going to get the
dmarti@zgp.org             injustice of the DMCA in front of the next
KG6INA                     jury.  Make noise.  It counts.

More information about the linux-elitists mailing list