thoughts, ideas, code and other things...

Friday, July 31, 2009

PyPaste - pastebins at your terminal

This weekend was quite eventful. It started with, unsuccessful trials in creating a GNOME applet in PyGTK and coming to a conclusion after consulting kr0y that, I should practice some glade+PyGTK before trying an applet. Well, that's for the time to come... for right now, I've got a useful tool made in Python for developers out there. I call it PyPaste.
Okay, one question, how many steps do you take to paste your code at a pastebin ? must be something like this -
  1. open a new tab in your browser
  2. copy-paste / browse for your file
  3. select a syntax highlighting mode
  4. copy-paste the url to irc/twitter/mail/wherever you wish
Hmm, so I wondered... could this process be made even shorter and more hacker friendly ?
And hence I came up with PyPaste this weekend which is a python script that helps you in paste-binning your code right from the terminal you're working on. No need to fire-up your browsers or switch windows. No need to drop a list box and select syntax highlighting mode for your code or even to see some ugly ads till it gets done. PyPaste is there to take care of all these thing. All you need to do is -

$ pypaste myfoobar.rb

have a look -

there you go, it recognised that we are pasting a shell script, and it highlighted a shell script's syntax :) effortlessness at 2 steps right :) !?

You can also select different pastebin services. Right now it supports ,, and Well, the list can be extended pretty easily if you study the source. All you need to do is figure out the right POST data for your pastebin and write a module for it. Put it in the modules directory and import it in, and also increment MAX and add an elif branch for your pastebin's prepare() function.
Well, all that might seem complicated right now, but I've tried my best to make it more hackable and extensible.

Now thats what a terminator or GNU screen user's screen looks like :) Geeky isn't it. You've got one irc opened up on top-right, manpage on left, one of the tabs can also open up a vim editor! In such a scenario, PyPaste comes handy and you really don't have to shift to other apps, all you need to do is issue a command and copy-paste to the irc channel where you wish to share your code.

I've put PyPaste on github - Get it here.
Direct link to the tarball -> here.

Right now it works well on linux. Haven't tested on a mac or windows. It might work on a mac after minor hacks, but for making it work on windows you'll have to do some more study of the code.

Happy pasting till then :)

DAMN! I just learnt that there is something called pastebinit, which already does the same thing. +1 for pastebinit for it supports many urls, +1 for PyPaste for it chooses syntax automatically. So, automatic syntax detection still remains a good advantage for PyPaste users.

Labels: , ,


Post a Comment

Subscribe to Post Comments [Atom]

<< Home