Simple Clipboard Management

(Day 14 of 30 Days of Blogging)

Greenclip is really useful for recording your clipboard history and showing a menu to switch between items.

Along the same lines I had an idea to write a tiny script that allows editing of the clipboard in vim. This has been handy when I need to quickly fix up some text before pasting it into a GUI application:

#!/bin/sh -e

file=`mktemp /tmp/clipboard-XXX`

xsel --clipboard > "$file"
xterm -e "$EDITOR -c 'set nofixeol' \"$file\""
xsel --clipboard < "$file"

rm "$file"

The nofixeol option prevents vim from adding a newline to the end of the clipboard, which is usually not desired.