Marcel's blog

Pastebin Klipper Script

Klipper is the KDE Desktop's clipboard management tool. It keeps track of your last few copy-and-pastes. But, in allowing you to configure actions that are selectable when the clipboard contents matches a regular expression, it opens the door to a world of useful little mini-applets.

My current favorite is one that I wrote to post the clipboard contents to Unfortunately, after whipping it up I ran across another script that does the same thing, but with a dependency on Ruby instead of Perl and no visual queue that the post operation has completed. Guess I should have dug a little deeper for prior art.

After using this script for a few months at work in IRC, I've observed that the script doesn't just automate a 30 second task into a 5 second task to save me 25 seconds. It completely changes my collaboration patterns. When debugging, I share more information with coworkers. I include a full stack trace instead of just the bare error message. I show entire command sequences with output in addition to giving a high-level summary in words. Once in a while, these extra bits of clarity will save hours when my correspondent notices something that wouldn't otherwise have been apparent. And it's now feasible to iterate with someone in a tweak-run-paste coding style.

To use klipper_pastebin yourself:

  • Put the script in your bin directory
  • Also put this rafb Perl script there, which does the grunt work
  • Add it to your list of klipper actions with a regex that matches everything

When you invoke it, it posts the clipboard contents. When the post is complete and the clipboard text has been exchanged for the pastebin URL, you'll get a little kdialog telling you so. You can then paste the URL into IRC, AIM, or whatever.

The rafb script is useful on its own from the commandline. Originally written by Sig Lange, I've slowly adapted and simplified it over the last couple years to meet my evolving requirements. It reads text from stdin or a file and prints the pastebin url on stdout. It's most useful when copying the text of interest would be difficult.

Beware of pasting private info! You may want to remove your name from the post for a little security-by-obscurity. At one point, I had the rafb script setup to post to a private pastebin protected by HTTP Basic Auth, with credentials pulled from a .netrc file. (But your correspondent would of course need access to the same private pastebin...)

Post a comment

Name or OpenID (required)

(lesstile enabled - surround code blocks with ---)