RSS

New Tools for JSON and Git

14 Nov

I had to share a couple of shiny new tools that I’ve recently incorporated into my workflow.

For JSON

jq

jq is great for chewing through JSON data. One of the best parts is that it’s written in portable C and it has zero runtime dependencies. You can download a single binary and drop it into your path like so.

wget http://stedolan.github.com/jq/download/linux_x86_64/jq -O /usr/local/bin/jq

chmod a+x /usr/local/bin/jq

To get a token from the Rackspace open cloud I used to parse the JSON with python. It’s effective but[t] ugly.

TOKEN=`curl -s -X POST https://identity.api.rackspacecloud.com/v2.0/tokens -d ‘{“auth”: {“passwordCredentials”: {“username”:”uname”, “password”:”pword”}}}’ -H “Content-type: application/json” | python -c ‘import json,sys; response=json.loads(sys.stdin.read()); print response["access"]["token"]["id"]‘`

With jq it’s much shorter, simpler, and easy to understand.

TOKEN=`curl -s -X POST https://identity.api.rackspacecloud.com/v2.0/tokens -d ‘{“auth”: {“passwordCredentials”: {“username”:”uname”, “password”:”pword”}}}’ -H “Content-type: application/json” | jq -r .access.token.id`

For Git

gitBash prompt builder

This is a website for generating a function to put in your .bashrc or .bash_profile file to show your Git / Hg / Subversion repository information in your bash prompt. I found it easiest to put the code generated by the builder into a separate file at ~/.bash_git. Then I source that file at the end of my .bash_profile with

source ~/.bash_git

This is great when you’re working with many git repos (or even just one) as it can, at a glance, let you know what branch you’re on, if there are changes, how many commits you’re ahead, etc. Plus it livens up your prompt with a little colour. There can be a second or two pause when you first cd to a git dir of a large repo but it’s totally worth it. Here are some examples of what my command line looks like now.

jclouds (openstack-cinder △ ) $ git commit -a -m “blah”

jclouds () (☢  labs/pom.xml) $ git add .

jclouds (master) +6 $ ls

Coda

For me, adding new tools to my daily workflow is a big deal. In addition to having the features I want/need, they need to be fast and efficient so they don’t get in the way. I’ve been using both of these for a few weeks now and I can say they definitely fit the bill. I highly recommend them!

 
Leave a comment

Posted by on November 14, 2012 in git, json

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: