After seeing a post on the github blog about David Baldwin using github as his blog I got to thinking about how much easier it would be to create my markdown posts offline and then commit them to some repository and have them show up as blog entries.
The comments for the github entry point out a number of people using various solutions to achieve an effect similar to what I want however I am somewhat loathe to give up on a web interface in general and Wordpress in particular. But this did get me thinking, what about a post-commit hook so after every commit a script examines the changed files and creates or edits posts as necessary. Google didn’t turn up much of anything in the way of making this happen and so I started thinking about how I would write my own solution.
As of right now I’m just in the planning stages but I did realize it would have to be a pre-commit hook on account of wanting to track the post id somewhere and the most logical place seems to be as some meta information at the top of the post. Currently I have the pre-commit hook reading the information I need to send about the post out of the file, the next step will be to figure out creating an XML object to send to the xmlrpc.php file of my Wordpress installation. In addition to dealing with hooks and xmlrpc1 I’m writing the script using Perl in order to get some hands on experience with it.
I’ll admit I’m not 100% sure I can make the script do what I want it to do but I’m certainly going to give it a shot because looking at the solutions eluded to in the comments of the post on github there doesn’t look to be a solution to satisfy me yet.
My initial planning has the username, password and xmlrpc url being stored as config options via git config username|password|xmlrpc while post related information is stored in the actual post file. I think the most likely hang up will be modifying the file which is about to be committed (by adding the post id) because I believe I’d actually have to create the post via xmlrpc, write the response into the file, stop the commit, add the post file back to the index and re-commit. There may also be a problem with the way xmlrpc expects the categories.2 Time will tell.
The folks at GitHub recently launched Gist which may well be the best code sharing/pasting tool ever. It has nice syntax highlighting and a plain user interface plus you can share more than one file in the same paste or gist. In addition to this you have the ability to create a ‘private’ gist. The quotes are because they are private only by obscurity not by any authentication logic. A SHA1 (I think) key is created and they use that as the url to you new, small git repository but they don’t show up in the view of all gists and a SHA1 is pretty unlikely to have it’s value guessed correctly.
Gist by itself is great news and a useful tool but the thing I find really appealing is that I can use it to keep simple text files in sync across multiple computers. This is incredibly useful to me because I typically track my work hours in a simple text file because our timesheet application is pretty horrendous to use and I want to deal with it as few times a week as possible. So I created a new private gist and added this time tracking text file and now I don’t have to worry about having my hours at work but not at home or vice versa because I can just pull from the private gist. Not only that but now my time tracking sheet is versioned so I don’t have worry about losing notes I make about how I spent my time in the unlikely event someone asks I can find it.
This was a grand breakthrough for me and I was quite pleased. Lately though I got to looking at some task tracking software and found some great ones but I am reluctant to pay for software I know I’m likely to stop using after a little while. Of the free options I didn’t find any which would allow me to easily sync my todo list from my home computer to my work computer. About this time I remembered a shell script I had used about a year ago which tracked all the information in simple text files. After a little looking I found Todo.txt - Task tracking for command line lovers. I dug around for the script on my computer and tried to update it but whenever I listed out my tasks I had this -e being printed in front of the first one. I’m fairly certain it was a misplaced sed argument but with all the regular expressions in the shell script I didn’t want to break things worse. I tried to search for the problem and came up empty on the mailing list but did find a link to a todo manager called Task which even provided an installer for Leopard!
Once I installed the package it was a simple matter of updating the configuration to write files to the directory where my time tracking gist was already located and TADA! easy syncing of time and tasks across multiple computers using the magic of the command line.
Apparently there’s been quite a buzz in the open source community lately about DVCSs in general and Git and Hg in particular. Up until pretty recently (sometime in the past week) I had totally missed the boat on this. However, I spent some time reading about them in a number of places, though apparently Dave Dribin’s writings are the only ones I bookmarked. None-the-less being a good the good little open source developer I pretend to be I thought I ought to at least tinker around with one of them and see what it was all about.
In mostly a snap decision I chose Git, though Linus’ highly entertaining tech talk may have influenced me. Either way, I already had a project I was working on, it isn’t exactly a compelling open source project but I didn’t have it under version control yet and it couldn’t hurt to get it somewhere. So having decided on Git I registered for a GitHub account and created a repository for it. The whole process was simple and easy, no problems there. Basically the premise behind GitHub is like a developer’s social network (well that and free Git repository hosting), you find a project you like and you follow (watch) it or you clone (fork) it. So then I saw John Resig’s tweet that his recently released Processing.js project was being hosted on GitHub and so I decided to fork it, look at the source and play around with it a bit.
The forking process was super easy, one click after being logged in and I had forked his project. No problems there but then I wanted to pull it down to my local machine or clone it so I had a working copy and here’s where I ran into problems. Executing git clone git@github.com:bryanjswift/processing-js.git generated the following output.
Initialized empty Git repository in /Users/.../Projects/processing-js/.git/
ERROR: Permission to bryanjswift/processing-js denied to bryanjswift/bjs-wordpress.
fatal: The remote end hung up unexpectedly
fetch-pack from 'git@github.com:bryanjswift/processing-js.git' failed.
After a little research I figured out the problem was basically the wrong RSA key was being sent to GitHub and since GitHub uses the RSA key to identify you and determine if you have access to the repository or not my access was being rejected for one or the other of the repositories. Which repository depended on which RSA key was first on the list of the output from ssh-add -l
I could probably have written a pre-hook and post-hook for each of the git repositories I wanted to acess but given the nature of the man who wrote Git I knew there had to be a better solution. So I start digging around and I find a guide to multiple GitHub accounts. I realize this isn’t really the situation I’m in but it does indeed work. I set up an entry in my ~/.ssh/config for each of the two projects each looking something like
Host github-bjs-wordpress
User git
Hostname github.com
IdentityFile /Users/.../.ssh/bjs-wordpress_rsa
Happily this worked once I used the new Host entries as the ssh hosts; so git@github.com:bryanjswift/processing-js.git became git@github-processing-js:bryanjswift/processing-js.git I could now access both my repositories. Hooray! Then I was poking around my account page on GitHub and found I can enter an RSA public key for my account and not just for each repository like I had already done. So I realize my mistake was entering myself as a collaborator on each repository and because I had done it that way I had to create multiple RSA keys for myself (GitHub makes each project collaborator on each project have a unique RSA key) which caused a mess.