Skip to content

Instantly share code, notes, and snippets.

@zev
Forked from andrewplummer/github_show.sh
Created September 18, 2012 03:55
Show Gist options
  • Save zev/3741159 to your computer and use it in GitHub Desktop.
Save zev/3741159 to your computer and use it in GitHub Desktop.
Open a link to a file in Github from the command line.
#!bin/bash
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
parse_git_remote() {
git remote -v | head -n 1 | sed 's/.*github.com:\(.*\).git .*/\1/'
}
if [ $# -eq 1 ]
then
branch=`parse_git_branch`
file=$1
elif [ $# -eq 2 ]
then
branch=$1
file=$2
else
echo "Need at least one argument"
exit 1
fi
remote=`parse_gite_remote`
url="https://github.com/$remote/blob/$branch/$file"
if (which xdg-open > /dev/null)
then
xdg-open $url &
else
open $url
fi
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment