Skip to content

Instantly share code, notes, and snippets.

@lamberta
Created January 5, 2014 07:39
Show Gist options
  • Save lamberta/8265545 to your computer and use it in GitHub Desktop.
Save lamberta/8265545 to your computer and use it in GitHub Desktop.
Git command line tool for quickly jumping to a project's web page or issue list.
#!/usr/bin/env bash
##
## Git command line tool for quickly jumping to a project's web page or issue list.
## Inspired by https://github.com/github/hub
## Save file as git-browse somewhere on your path.
print_help() {
echo "Usage: git browse [options]"
echo " -i, --issues Navigate to the project's issue page."
}
## parse command line args
if [[ $# > 0 ]]; then
case "$1" in
"-i" | "--issues") ISSUES_FLAG=1;;
"-h" | "--help") print_help; exit 0;;
*) print_help; exit 1;;
esac
fi
REMOTE_URL=$(git remote -v | head -n1 | cut -f2 | sed -e 's/\(\.git\).*$//g')
if echo "$REMOTE_URL" | grep "git@" > /dev/null; then
REMOTE_URL="${REMOTE_URL#git@}"
REMOTE_URL=$(echo "$REMOTE_URL" | tr ':' '/')
REMOTE_URL="https://$REMOTE_URL"
fi
if [ -n "$ISSUES_FLAG" ]; then
REMOTE_URL="$REMOTE_URL/issues"
fi
open "$REMOTE_URL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment