Skip to content

Instantly share code, notes, and snippets.

@jah2488
Last active February 3, 2016 21:39
Show Gist options
  • Save jah2488/521079054c02bdc62119 to your computer and use it in GitHub Desktop.
Save jah2488/521079054c02bdc62119 to your computer and use it in GitHub Desktop.
A custom git "plugin" that allows you to open git repos on Github.com by saying "git open" from inside the repo. This file needs to be chmod +x and needs to be in your path and needs the extension removed.
#!/usr/bin/env bash
# vim: set ft=ruby:
# This file executes as a bash script, which turns around and executes Ruby via
# the line below. The -x argument to Ruby makes it discard everything before
# the second "!ruby" shebang. This allows us to work on Linux, where the
# shebang can only have one argument so we can't directly say
# "#!/usr/bin/env ruby --disable-gems". Thanks for that, Linux.
#
# If this seems confusing, don't worry. You can treat it as a normal Ruby file
# starting with the "!ruby" shebang below.
exec /usr/bin/env ruby --disable-gems -x "$0" $*
#!ruby
remote = `git remote -v`
unless remote.empty?
url_pieces = remote.scan(/github\.com:(.*)\.git/)
url = "https://github.com/#{url_pieces.first.first}"
`open #{url}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment