-
-
Save zev/3741159 to your computer and use it in GitHub Desktop.
Open a link to a file in Github from the command line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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