Created
February 19, 2013 11:11
-
-
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!
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
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/[email protected]//' -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/[email protected]://' -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