Author: "Type git open to open the repo website (GitHub, GitLab, Bitbucket) in your browser."
Go to file
Edward Thomson e3ce014bfa Add support for Visual Studio Team Services and Team Foundation Server (#93)
* Parse remotes as URLs or SCP-style paths

Instead of trying to strip on ':' and '/' to simplify a URL, actually
switch based on whether the remote path is a URL ("scheme://host:port/path")
or an SCP-style path (user@host:path) and parse them separately.

This allows us to handle custom ports in HTTP and HTTPS, but ignore
custom ports in an SSH url and HTTP remotes, instead of always upgrading
them to HTTPS.

* Introduce tests for Visual Studio Team Services

Add tests for Visual Studio Team Services (VSTS) and Team Foundation
Server (TFS).  VSTS suggests remote paths in two formats: HTTPS URLs
or SSH URLs (including port number).  TFS is an on-premises product
which - when running as an HTTP endpoint - defaults to port 8080.

* Branch selection in Visual Studio Team Services

VSTS and TFS URLs end in '/_git/RepositoryName` (with 0 or more leading
folders of hierarchy in front of that.)  Detect these from the `_git` in
the penultimate folder of the path.  Append branch information to VSTS
and TFS URLs.

Since VSTS and TFS use a query string to select a branch, instead of
including it in the server path, the `providerBranchRef` for other
services was changed to include the leading `/`, and now the `openurl`
and `providerBranchRef` are simply concatenated, to avoid an incorrect
trailing `/` for the VSTS and TFS branch URLs.

* Issues for Visual Studio Team Services

Provide issue support for VSTS and TFS, modifying the URL from the
`_git` endpoint to the `_workitems` endpoint and appending the `id`
query string.

* README: add VSTS and TFS support
2017-11-30 16:23:52 -08:00
test Add support for Visual Studio Team Services and Team Foundation Server (#93) 2017-11-30 16:23:52 -08:00
.editorconfig Add license file (#90) 2017-06-23 06:51:58 -07:00
.gitignore Add BB sourceview tests from PR #26 (#81) 2017-06-18 13:38:43 -07:00
.gitmodules Add a test suite (#78) 2017-06-16 15:57:49 -07:00
.travis.yml Add a test suite (#78) 2017-06-16 15:57:49 -07:00
git-open Add support for Visual Studio Team Services and Team Foundation Server (#93) 2017-11-30 16:23:52 -08:00
git-open.plugin.zsh Switch to prepending ourself to $PATH 2016-07-11 16:44:10 -07:00
issue_template.md add issue_template 2017-06-18 13:43:58 -07:00
LICENSE.md Add license file (#90) 2017-06-23 06:51:58 -07:00
markdownlint.json 1.1.0 2016-07-22 02:01:22 -04:00
package.json v1.5.0 2017-10-27 14:13:23 -07:00
README.md Add support for Visual Studio Team Services and Team Foundation Server (#93) 2017-11-30 16:23:52 -08:00

git-open Build Status

Type git open to open the repo website (GitHub, GitLab, Bitbucket) in your browser.

git open2015-01-24 13_51_18

Usage

git open [remote-name] [branch-name]

git open --issue

(git open works with these hosted repo providers, git open --issue currently only works with GitHub, Visual Studio Team Services and Team Foundation Server)

Examples

$ git open
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH

$ git open someremote
# opens https://github.com/PROVIDED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH

$ git open someremote somebranch
# opens https://github.com/PROVIDED_REMOTE_USER/CURRENT_REPO/tree/PROVIDED_BRANCH

$ git open --issue
# If branches use naming convention of issues/#123,
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/issues/123

Installation

Basic install

The preferred way of installation is to simply add the git-open script somewhere into your path (e.g. add the directory to your PATH environment or copy git-open into an existing included path like /usr/local/bin).

Install via NPM:

npm install --global git-open

Windows Powershell

Save git-open anywhere, say as ~/Documents/Scripts/git-open.sh and define a function in your Powershell profile (see ~/Documents/WindowsPowerShell/profile.ps1) like this:

function git-open { cmd /c "C:\Program Files\Git\usr\bin\bash.exe" "~/Documents/Scripts/git-open.sh" }
Set-Alias -Name gop -Value git-open

Windows with cmd terminal

Save the git-open script in any place accessible via your %PATH% environment var.

ZSH

Antigen

Add antigen bundle paulirish/git-open to your .zshrc with your other bundle commands.

Antigen will handle cloning the plugin for you automatically the next time you start zsh, and periodically checking for updates to the git repository. You can also add the plugin to a running zsh with antigen bundle paulirish/git-open for testing before adding it to your .zshrc.

Oh-My-Zsh

  1. cd ~/.oh-my-zsh/custom/plugins
  2. git clone https://github.com/paulirish/git-open.git
  3. Add git-open to your plugin list - edit ~/.zshrc and change plugins=(...) to plugins=(... git-open)

Zgen

Add zgen load paulirish/git-open to your .zshrc file in the same function you're doing your other zgen load calls in. ZGen will take care of cloning the repository the next time you run zgen save, and will also periodically check for updates to the git repository.

zplug

zplug "paulirish/git-open", as:plugin

Supported remote repositories

git-open can automatically guess the corresponding repository page for remotes (default looks for origin) on the following hosts:

  • github.com
  • gist.github.com
  • gitlab.com
  • GitLab custom hosted (see below)
  • bitbucket.org
  • Atlassian Bitbucket Server (formerly Atlassian Stash)
  • Visual Studio Team Services
  • Team Foundation Server (on-premises)

GitLab support

To configure GitLab support you need to set some options.

option name description example
gitopen.gitlab.domain The (web)domain name that will work for most of the people gitlab.example.com
gitopen.gitlab.ssh.domain A specific ssh domain name, if needed git.example.com
gitopen.gitlab.ssh.port A specific ssh port, if needed 10022
# use --global to set across all repos, instead of just the local one
git config [--global] gitopen.gitlab.domain [value]
git config [--global] gitopen.gitlab.ssh.domain [value]
git config [--global] gitopen.gitlab.ssh.port [value]

If your Gitlab custom hosted is serving http you can also specify this:

# use --global to set across all repos, instead of just the local one
git config [--global] gitopen.gitlab.protocol http

Alternative projects

See hub for complete GitHub opening support. It's the official GitHub project and provides hub browse.

Homebrew has an alternate git-open that only works with GitHub but can open user profile pages, too.

@gerep has an alternate git-open that works with a few providers. Of note, it opens the default view for BitBucket instead of the source view.

And, of course, jasonmccreary's original gh from which this plugin was forked.

Thanks

jasonmccreary did the initial hard work. Since then, many contributors have submitted great PRs.

Contributing & Development

Please provide examples of the URLs you are parsing with each PR.

You can run git-open in echo mode, which doesn't open your browser, but just prints the URL to stdout:

env BROWSER='echo' ./git-open

Testing:

You'll need to install bats, the Bash automated testing system. It's also available as brew install bats

git submodule update --init # pull in the assertion libraries

# Run the test suite once:
bats test  # or `npm run unit`

# Run it on every change with `entr`
brew install entr
npm run watch

License

Copyright Jason McCreary & Paul Irish. Licensed under MIT. http://opensource.org/licenses/MIT

Changelog

  • 2017-06-17 - test suite added
  • 2016-07-23 - readme -- fix oh-my-zsh install instructions
  • 2016-07-22 - 1.1.0, update and add linters for package.json, readme. Re-publish to NPM.
  • 2016-07-11 - Changelog started (readme formatting and installation instructions updated)