twenty four merry days of Perl Feed

Don't Get Kickbanned

App::Nopaste - 2011-12-14

IRC is great!

Over the years, I've heard a lot of loose talk about how IRC is a cesspool of bad attitudes, filthy language, and unhelpful people who would sooner stab you in the face than look at your problem code. This is entirely untrue!

Well, at any rate, it's not entirely true. Those people would probably like to stab you in the face, but only if you give them an excuse. Probably the biggest offense you can commit – other than just being a known lazy bastard – is trying to paste your whole six thousand line program to the channel.

You have to communicate the program, though, and programs can be big. Even if you boil your problem down to a simple test case, it might be twenty lines, and a twenty line paste will still get you kicked off the channel pretty darn fast. To work around the problem, most IRC channels have paste bins. A paste bin is a web site where you can paste your huge code listing or exception report so that you don't have to paste it to IRC. Some paste bins have IRC bots that report to the channel that you just pasted something. Others provide you with a URL to a pretty page showing your code listing.

...but pasting into a web browser is hard!

If you boil your code down to a twenty line test case, it's pretty easy to copy and paste into your web browser. When you really can't reduce things below a few hundred lines, it gets more complicated – especially if you're editing things in a terminal, over ssh, in screen. You could copy the file around, open it in something with a "Select All" option, and so on… or you could just enjoy yet another minor improvement to your life brought to you by unix pipes and Perl.

App::Nopaste provides nopaste, a simple command-line program that takes standard input, writes it to a paste bin, and prints the URL where your paste can be found. It is the DBI of paste bins, with multiple backends for whichever paste bin you like best. If your favorite paste bin isn't working, it will fall back to backup choices. It works with named files or standard input:


1: 
2: 
3: 
4: 
5: 

 

~/tmp$ nopaste bangbang.pl
http://gist.github.com/1350212

~/tmp$ ./bangbang.pl | nopaste
http://gist.github.com/1350213

 

As you can see here, I use nopaste to paste to Gist, Github's paste bin. Each paste into Gist becomes a Git repository, and can have multiple revisions, multiple files, and comments. It's really nice. To make sure my Gist pastes are associated with my Github account, so I can edit (and delete!) them, I just make sure my Github credentials are set in my ~/.gitconfig file and it all works:


1: 
2: 
3: 

 

[github]
user = rjbs
token = 23bea31203eba10ea90987876faeeda72

 

Unfortunately, Github isn't always up. Its availability is pretty good, but when I'm flailing and losing my patience so much with a bug that I've gone into a horrible place like IRC to look for help, the last thing I want is to find out that my paste bin is broken, too. It's easy to configure fallbacks. I have this line in my .zshrc:


1: 
 

export NOPASTE_SERVICES='Gist Pastie Snitch Shadowcat'
 

When Gist isn't working, nopaste will try a few more fallbacks, one of which is almost certain to work.

Options, options, options!

Gist doesn't do IRC announcements of pastes, but lots of other paste bins do, so you need a way to tell nopaste where to announce it. There are switches for that.

With Gist, you'll need to copy and paste the URL into IRC by hand – but if you install Clipboard and use --copy, nopaste will copy the URL to the clipboard automatically. You can open the URL automatically, mark the paste as private, or set other data about your paste so that it looks just right.

See Also

Gravatar Image This article contributed by: Ricardo Signes <rjbs@cpan.org>