git_url script — formatting git ssh remote output for quicker copy & paste to browser

I wanted an easier way to open a git repo’s github page. The git remote -v command works alright but then I have to edit the link in the address bar after coping and pasting.

git remote -v
-> origin (fetch)
-> origin (push)

So I made a little script that I called git_url:

#!/usr/bin/env bash
git remote -v | grep push | ruby -ne 'puts "GitHub URL: " + $_.split[1].gsub("\.git", "").gsub("git\@", "www\.").gsub(":", "/")'

and symlinked it to my usr/local/bin

cd /usr/local/bin/
sudo ln -s /Users/bobmeow/Development/scripts/git_url

and now I can type ‘git_url’ when I am in a git directory and get it’s url:

-> GitHub URL: