manicwave

Surf the wave

Git Clone From Safari

Permalink

It is often the late night exploration of code in the wild that gives rise to these cute little hacks.

With my wrist tiring of flipping between safari and terminal, the following was born.

Goal

git clone the repository ref found in the system pasteboard

Scenario

When perusing gitHub, I'll find something I want to check out. I click on the "clone" button which copies the git reference to the clipboard. I typically flip over to a terminal session, change directory to my favorite dumping grounds, and do a git clone Cmd-V enter.

Here's a script that will do all of that. The secret sauce is teaming this up with something like FastScripts (an excellent status bar accessory).

#!/bin/sh
REPO=`pbpaste`
DUMPDIR=~/dev/extern

cd $DUMPDIR && /usr/local/git/bin/git clone $REPO
EXITCODE=$?
if [ "$EXITCODE" -ne "0" ]; then
    echo "Download of $REPO failed: $EXITCODE" | /usr/local/bin/growlnotify -p 1 "Clone Failed"
else
    echo "Download of $REPO successful" | /usr/local/bin/growlnotify "Clone Succeeded"
fi

What's happening here?

First we grab the repo reference from the pasteboard using pbpaste. Then we cd to our dumping grounds, execute the git clone. If it fails (because it's already there, no access, etc) we use growlnotify to throw up the appropriate message.

I bind this script in ~/Library/Scripts/Applications/Safari and then use Cmd- Shift-C - so click to copy, Cmd-Shift-C to clone.