Skip to content

Instantly share code, notes, and snippets.

@rondevera
Created October 19, 2010 19:45
Show Gist options
  • Select an option

  • Save rondevera/634946 to your computer and use it in GitHub Desktop.

Select an option

Save rondevera/634946 to your computer and use it in GitHub Desktop.
OS X: Opens the specified file/directory in GitHub via your browser
# Usage from within a Git repo:
#
# hubb public/javascripts/app.js
# # Opens `https://github.com/<repo>/blob/<branch>/public/javascripts/app.js`
# # in your browser.
#
# hubb
# # Opens `https://github.com/<repo>` in your browser.
hubb(){
repo=$(git config remote.origin.url | sed "s/^git@github\.com:\(.*\)\.git$/\1/")
branch=$(cat .git/HEAD | sed "s/.*\/\(.*\)$/\1/")
if [ $1 ]; then
kind=$([[ $1 =~ \/$ ]] && echo "tree" || echo "blob")
open "https://github.com/$repo/$kind/$branch/$1"
else
# Like `hub browse`: https://github.com/defunkt/hub
open "https://github.com/$repo/tree/$branch"
fi
}
@dstrelau
Copy link
Copy Markdown

This would make a good addition to the git browse sub-command of hub.

@rondevera
Copy link
Copy Markdown
Author

Definitely; I called it hubb as shorthand for hub browse, but with the feature I wanted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment