Linux Clipboard Snippets
September 4th, 2009 By: DanielWhenever I find myself typing the same thing over and over again, I have to come up with some way to avoid the repetition. And one thing I do a lot is fill out web forms that require things like credit card numbers and unique email addresses. For a while I tried using Parcellite (a clipboard manager) but it wasn’t really designed for what I wanted to use it for. Finally with the inspiration of this thread I was able to cobble together a solution that does just what I want.
First I created a snippets directory and filled it with files that contained the text to insert or scripts to generate the desired text:
$ cd ~/.snippets $ ls -1 credit_card email @example.com phone RAILS_ENV=test sql_create sql_permissions $ cat credit_card 4111111111111111 $ cat sql_permissions GRANT ALL PRIVILEGES ON .* TO ''@'localhost' IDENTIFIED BY ''$ cat phone #!/usr/bin/env ruby print (1..12).map { i i == 4 i == 8 ? '-' : rand(10).to_s}.join
Then I put this little script in ~/bin:
#!/bin/bash # http://bbs.archlinux.org/viewtopic.php?id=71938 DIR=${HOME}/.snippets DMENU_ARGS="-i -fn -*-terminal-*-*-*-*-18-*-*-*-*-*-*-*" # xfontsel to select font FILE=`/bin/ls $DIR | /usr/bin/dmenu ${DMENU_ARGS}` if [ -x ${DIR}/${FILE} ]; then #executable echo -n `${DIR}/${FILE}` | xsel -b -i elif [ -f ${DIR}/${FILE} ]; then cat ${DIR}/${FILE} | xsel -b -i fi xdotool key ctrl+v # for non-console xdotool key ctrl+shift+v # for console
And then I mapped that script to a handy key combination in compiz. So now whenever I need a test credit card number, phone number, or email address I can just do
Notes and caveats:
- I had to aptitude install some packages to get dmenu and xdotool to work.
- dmenu is ugly and has no mouse support.
- Pasting into vim has occasional issues.

The Sevier River Water Users Association (SRWUA) in Central Utah are pioneers in the use of the Real-Time Web. For the past 10 years SRWUA has been delivering real-time water flow data to the public via the website www.SevierRiver.org.
More that 100 remote, solar-powered, stations record wate...