Giter Site home page Giter Site logo

git-open's Introduction

git-open Build Status

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

Demo of git open in action

Usage

git open [remote-name] [branch-name]
    # Open the page for this branch on the repo website

git open --commit
git open -c
    # Open the current commit in the repo website

git open --issue
git open -i
    # If this branch is named like issue/#123, this will open the corresponding
    # issue in the repo website

git open --print
git open -p
    # Only print the url at the terminal, but don't open it

(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

$ git open --print
# prints https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH

$ git open --suffix pulls
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/pulls

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

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.

  1. git clone https://github.com/paulirish/git-open.git $ZSH_CUSTOM/plugins/git-open
  2. Add git-open to your plugin list - edit ~/.zshrc and change plugins=(...) to plugins=(... git-open)
  3. source ~/.zshrc

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 "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)
  • AWS Code Commit

Configuration

See the man page for more information on how to configure git-open.

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.

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

Related projects

License

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

Changelog

  • 2018-12-03 - 2.1.0 shipped.
  • 2017-12-01 - 2.0 shipped. Breaking change: Gitlab configuration handled differently.
  • 2017-12-01 - Configuration for custom remote added
  • 2017-11-30 - Support for VSTS Added
  • 2017-10-31 - --issue and -h added
  • 2017-10-30 - Configuration for custom domains added
  • 2017-10-30 - WSL support added
  • 2017-06-16 - Introduced a test suite in BATS
  • 2017-06-15 - Entire script rewritten and simplified by @dermagia
  • 2016-07-23 - Readme: fix oh-my-zsh install instructions
  • 2016-07-22 - 1.1.0 shipped. update and add linters for package.json, readme.
  • 2016-07-11 - Readme formatting and installation instructions updated. Changelog started

git-open's People

Contributors

4u6u57 avatar bbeardsley avatar crossroad0201 avatar davidosomething avatar derimagia avatar elim avatar eush77 avatar ffes avatar glostis avatar jasonmccreary avatar jaxwood avatar kyuden avatar lovef avatar naereen avatar neoascetic avatar nwinkler avatar olegafx avatar orestisfl avatar paulirish avatar pborenstein avatar pierstoval avatar rcmachado avatar rec avatar redwolves avatar ryuheechul avatar sowmiyamuthuraman avatar supersandro2000 avatar trentrand avatar unixorn avatar victor141516 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-open's Issues

Support for Gitlab?

Is there any plans to support Gitlab? Specially those repos that are self hosted.

Pipe stdout and stderr to /dev/null

On Ubuntu I get hundreds of lines of output when firefox starts up from the command line. To prevent, that, change the 2nd to last line of the script to:

$open $giturl &> /dev/null

hub

Is there any way you could get this into hub? It seems more like a missing feature in hub than its own feature! hub has a browse command to open the repo / issues / wiki, but not the pages. It's pretty neat, though.

https://github.com/github/hub

bad substitution

I get the following when I type git open

/Users/arian/.oh-my-zsh/custom/plugins/git-open/git-open: line 99: ${ssh_optcode^^}: bad substitution

If an incorrect URL is opened, please provide the following so we can write a test:

Example clone url:

[email protected]:abc/abc-dfg.git

Example branch name:

one-to-one-3

Expected web URL:

It went to the right url

https://github.foo.example.com/abc/abc-dfg/tree/one-to-one-3

Add a --new-pr flag to open pull-request page

My common workflow is:

  1. create a branch, commit, push
  2. git open
  3. click on "Compare & pull request" button
  4. once the page loads, fill it out and submit PR

There's not much value in me opening the branch page. ideally a flag like --new-pr would open the create-a-pull-request link directly.

So:

env BROWSER=echo git open
# https://github.com/GoogleChrome/lighthouse/tree/bootuptime-edit

env BROWSER=echo git open --new-pr
# https://github.com/GoogleChrome/lighthouse/compare/bootuptime-edit?expand=1

anyone else interested in this one? (looks like #64 basically wanted the same thing)

do bitbucket/gitlab/vsts have similar URLs?

Rewrite in Python?

The sourcebase in bash hasn't been holding up well to all of the string manipulation.

I think it could use a rewrite. Plus it'd open us up to write some tests for all the string acrobatics it's gained.

Personally I'd prefer JavaScript but requiring node seems excessive. Python seems like a reasonable choice, but I'm personally open.

I won't have time to do this myself, so it's open to anyone interested.

WSL support?

Could you please add support for bash on Windows?

no URL was open...

Hi, I'm using arch + tilix + ohmyzsh and it don't work...

any error message...

someone know how fix it?

even if I use:
npm install --global git-open

Thanks in advance,

[Feature Request] Open CI URL

Add a flag to open CI/CD tool URL:

git open --cx

Based on the contents of the repo we could identify the CI URLs. However, there are a lot of limitations. For travis, circleci etc. we could identify the URL easily but for self-hosted CI/CD tools like GoCD, Jenkins it will be difficult.

Adding this idea here so that someone could come up with a better way to do it. Let me know if this feature makes sense.

An option to just print and not open the link

How about git open --print.

2 use cases:

  1. I wish to use the URL in some other script
  2. I have multiple browser windows open at any point in time, So I wish to open it in a particular window. git open --print | pbcopy would help a lot

git open a particular file

I was just thinking it would be cool to be able to do something like:

git-open /path/to/file

and have the browser open that file in that branch that one was in ...

-Requirements?- OMZ Config

I am having trouble getting this to work with the .oh-my-zsh install instructions. First question does this require hub to be installed?

$  git --version
git version 2.6.4 (Apple Git-63)
$ git open
git: 'open' is not a git command. See 'git --help'.

Did you mean one of these?
    clean
    clone
    notes
    prune

New release

Now that #132 has been landed, I'd appreciate a new release, so I don't need to install from git.

Thanks!

git open pr

It would be nice to be able to run git open pr and get the first PR it finds for the current branch.

The behavior of `git open issue` does not match README

The readme states:

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

However, the current behaviour is better explained by:

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

The behaviour in the README makes sense and is intuitive, so it would be good if the actual program could match that.

Fish shell compatibility

I would like to use git-open with Fish but it doesn't worked.

I installed it with fisher plugin manager.

Do you think it could be possible to add git-open support to Fish?

git open current upstream

If I have multiple remotes, and I do a git push -u other branchname, I would expect 'git open' to open whatever the current remote is, as opposed to using origin.

Atlassian Stash support

It's true that HTTP URLs contain /scm/, but that's for read-only access. If you're working with a repo that you can push to, it has an SSH URL that looks like this:

ssh://[email protected]:7999/foo/ken-homedir.git

where foo is a 3-or-4-letter key for the Project (a grouping of repositories).

In this case, perhaps recognizing the port number or the global format of the URL might be necessary. Open to a patch for that?

Add support for Arch User Repository (AUR)

If an incorrect URL is opened, please provide the following so we can write a test:

Example clone URL:

https://aur.archlinux.org/git-open-git.git or ssh://[email protected]/git-open-git.git

Example branch name:

master

Expected web URL:

https://aur.archlinux.org/packages/git-open-git

It will be a simple fix. We can add a simple if condition with a regex to check if the URL is of the AUR, and if it is, we just need to append the /packages/ part to the URL.

For example,
URL opened by git open: https://aur.archlinux.org/git-open-git
Actual URL: https://aur.archlinux.org/packages/git-open-git

if [ $domain == "aur.archlinux.org" ]; then
  domain="$domain/packages"
fi

Simplify bitbucket src view URL

So bitbucket is supposed to be able to view a branch URL like:

bitbucket.com/user/repo/src/mybranch/

However we're currently mimicking the URL that the site generates like:

bitbucket.com/user/repo/src/commitsha/?at=branchname

I'd prefer to use the simple version, as @derimagia's rewrite does. However it turns out there's a problem with branches including a / (slash) in the name.


I've filed this issue upstream: https://bitbucket.org/site/master/issues/14422/source-view-url-of-branch-name-with

Until that's resolved, I think we'll need the longer URL (unless someone identifies a better workaround).

So for now, this is our downstream tracking issue until the BB one is fixed. ๐Ÿ˜‰

cc @nwinkler @davidosomething

Write a man page

git open --help tries to open the man page for the command but there is no man page.

Hopefully somebody is brave enough to write one!

Not sure if the source of such a man page should be troff or something better like restructuredtext or markdown (which can be converted to man pages with rst2man or md2man, but require additional build dependencies)

A large part of the documentation could come from the README.md

Failing gitlab tests

We have two failing tests after the rewrite has landed

 โœ— gitlab: separate domains
   (from function `assert_output' in file test/test_helper/bats-assert/src/assert.bash, line 239,
    in test file test/git-open.bats, line 186)
     `assert_output "https://gitlab.example.com/namespace/project"' failed
   fatal: remote origin already exists.
   Switched to a new branch 'master'

   -- output differs --
   expected : https://gitlab.example.com/namespace/project
   actual   : https://git.example.com/namespace/project
 โœ— gitlab: ssh://git@host:port origin
   (from function `assert_output' in file test/test_helper/bats-assert/src/assert.bash, line 239,
    in test file test/git-open.bats, line 220)
     `assert_output "https://repo.intranet/XXX/YYY"' failed
   fatal: remote origin already exists.
   Switched to a new branch 'master'

   -- output differs --
   expected : https://repo.intranet/XXX/YYY
   actual   : https://repo.intranet/7000/XXX/YYY
   --

@derimagia how did you want to handle these guys?

Opens ssh.github.com since upgrading

Since upgrading (from which version I'm not sure), git open is opening URLs at a nonexistent ssh subdomain. The repos were all cloned with SSH, in case that has something to do with it. This was never an issue before...

Thanks. Let me know if you need additional info.


If an incorrect URL is opened, please provide the following so we can write a test:

Example clone url:

https://github.com/goodguyry/postcss-tidy-columns

Example branch name:

master

Expected web URL:

https://github.com/goodguyry/postcss-tidy-columns

Actual web URL:

https://ssh.github.com/goodguyry/postcss-tidy-columns

Support for detached HEAD state?

If you're in a detached HEAD state, ${2:-$(git symbolic-ref -q --short HEAD)} gives nothing.

If you use git symbolic-ref HEAD and it fails with fatal: ref HEAD is not a symbolic ref, you're in a detached HEAD.

Being in this state, git status gives you, for example, HEAD detached at 1.1b1. You can extract the tag/branch/commit after HEAD detached at and complement the https://github.com/ORG/REPO/tree/EXTRACTED and be able to open repositories in detached HEAD. It worked with the short hash.

...or if you're into an even more pragmatic approach, do an if grep -v 'HEAD detached'; then and extract the hash. :)

More info about detached HEAD: https://stackoverflow.com/a/5772882

Windows cmd installation instructions do not work

The readme says

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

but that doesn't work. Why would it as the git-open script uses !# which does not work on cmd. It no doubt does work in WSL. Unless git should find it and handle it? I plonked mine in c:\windows\system32, naughty by it should work there AFAIK

However npm I -g git-open installs it just fine.

Sadly though, using nvm-windows loses global installs when you switch versions ;(

Page not found

I was testing this plugin with my repo and it opened the URL https://github.com/theoriginalbit/repo//master instead of https://github.com/theoriginalbit/repo/tree/master resulting in GitHub 404'ing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.