Skip to content

Instantly share code, notes, and snippets.

@vitaminmoo
Created August 3, 2012 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitaminmoo/3242809 to your computer and use it in GitHub Desktop.
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.
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