Skip to content

Instantly share code, notes, and snippets.

@freegenie
Created February 19, 2013 11:11
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 freegenie/4984950 to your computer and use it in GitHub Desktop.
Save freegenie/4984950 to your computer and use it in GitHub Desktop.
bounch of bash functions to speed up collaborations on git based project hostings (github and bitbucket for now). Source it to your shell environment and enjoy!
function last-commit() {
git log --format=%H -n 1
}
function last-file-change() {
git rev-list --max-parents=1 --max-count=1 --format=oneline HEAD -- $1 | cut -d " " -f 1
}
function annotate-file() {
# annotate-commit $(last-file-change $1)
open $(url_to_blob $1)
}
function is_github() {
test "$(git remote -v | grep origin | grep github)" != ""
}
function remote_project_url() {
if is_github ; then
github_project_url
else
bitbucket_project_url
fi
}
function bitbucket_project_url() {
URL=$(PROJ=$(git remote -v | grep origin | grep push | awk '{ print $2}' | sed -e 's/git@bitbucket.org//' -e 's/\.git//' -e 's/ssh\:\/\///'); echo "https://bitbucket.org$PROJ" ); echo $URL$1
}
function github_project_url() {
URL=$(PROJ=$(git remote -v | grep origin | grep push | awk '{ print $2}' | sed -e 's/git@github.com://' -e 's/\.git//'); echo "https://github.com/$PROJ" ); echo $URL$1
}
function url_to_commit() {
if is_github ; then
github_project_url "/commit/$1"
else
bitbucket_project_url "/commits/$1"
fi
}
function url_to_blob() {
P=$1
L=$(last-file-change $1)
if is_github ; then
github_project_url "/blob/$L/$P"
else
bitbucket_project_url "/src/$L/$P"
fi
}
function annotate-commit() {
open $(url_to_commit $1)
}
function annotate-last-commit() {
annotate-commit `last-commit`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment