Created
August 3, 2012 00:53
-
-
Save vitaminmoo/3242809 to your computer and use it in GitHub Desktop.
Bash sub to return the github url the current git working tree, or a specific file if specified. Currently links to HEAD of the default branch.
This file contains 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
ghu() { | |
if [ $(git rev-parse --is-inside-work-tree) = 'true' ] | |
then | |
test ! -z "$1" && file=$(readlink -f "$1") | |
url=$(git remote -v | sed '/fetch/d; s/.*\@//; s/ .*//; s/:/\//; s/^/https:\/\//') | |
top=$(git rev-parse --show-toplevel) | |
echo $url/tree/master$(echo $file | sed "s.^$top..") | |
else | |
echo "not inside a git working directory" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment