Code Monkey home page Code Monkey logo

open-browser-github.vim's Introduction

open-browser-github.vim

About

Opens GitHub URL of current file, etc. from Vim. Also supports GitHub Enterprise.

Install

This plugin requires:

Usage

There are 4 commands.

:OpenGithubFile

Opens a specific file in github.com repository(it also opens in the current branch by default).

" Opens current files URL in github.com
:OpenGithubFile
" Opens current files highlighted place in github.com 
:'<,'>OpenGithubFile
" Opens a specific file in github.com
:OpenGithubFile PATH/TO/FILE

:OpenGithubIssue

Opens a specific Issue.

" Opens current repositories Issue #1
:OpenGithubIssue 1
" Opens a specific repositories Issue #1
:OpenGithubIssue 1 tyru/open-browser.vim
" Opens current repositories Issue List
:OpenGithubIssue
" Opens a specific repositories Issue list
:OpenGithubIssue tyru/open-browser.vim

:OpenGithubPullReq

This command opens /pulls page when it has no argument. Otherwise, it does entirely the same thing as :OpenGithubIssue since GitHub redirects /issues/1 to /pull/1 if #1 is a Pull Request.

:OpenGithubProject

Opens a project page.

" Opens current opening file's repository.
" ex) https://{hostname}/{user}/{name}
:OpenGithubProject

" Opens current opening file's repository.
" ex) https://{hostname}/tyru/open-browser.vim
:OpenGithubProject tyru/open-browser.vim

GitHub Enterprise setting

If you have hub command

If you have hub command in your PATH, openbrowser-github executes the following command:

hub browse -u -- {path}

And it will open the returned (output) URL.

If you don't have hub command

If you don't have hub command in your PATH, openbrowser-github tries to get each part of URL from the following gitconfig key:

  • hub.host

You can specify GitHub Enterprise repository URL by setting above keys in gitconfig.

For example, you can set hub.host by executing the following command in your git repository which you want to specify GitHub Enterprise repository URL.

git config --local hub.host my.git.org

open-browser-github.vim's People

Contributors

glidenote avatar haya14busa avatar k0kubun avatar layzie avatar mono0x avatar obcat avatar rhysd avatar shatur avatar take avatar tmsanrinsha avatar tyru 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

open-browser-github.vim's Issues

Support copy github link

Sometimes we want to share GitHub link to others. If this plugin supports copy GitHub link, it saves the trouble of opening browser , copying from address bar and closing browser tab immediately.

:OpenGithubProject ignores argument

With this .vimrc:

set nocompatible

call plug#begin('~/.vim/bundle/')

Plug 'tyru/open-browser.vim'
Plug 'tyru/open-browser-github.vim'

call plug#end()

:OpenGithubProject always opens current repo, even when called with an argument.

E.g. calling :OpenGithubProject tyru/open-browser.vim opens mwgkgk/dotfiles, if I call it from my .vimrc :) If called outside of a valid repo, open-browser prints the following complaint:

open-browser doesn't know how to open 'Usage: hub browse [-uc] [[<USER>/]<REPOSITORY>|--] [<SUBPAGE>]'.

Last update broke the plugin

Hi, I'm using Neovim. When I updated the plugin this happens everytime I executed a OpenGitHub* command. Probably related to the recent changes on https://github.com/tyru/open-browser.vim/

Error detected while processing function openbrowser#github#file[3]..<SNR>368_call_with_temp_dir[12]..<SNR>368_cmd_file[1]..<SNR>368_parse_cmd_file_args[10]..<SNR>368_get_repos_relpath:         
line    3:                                                                                                                                                                                        
E117: Unknown function: s:git                                                                                                                                                                     
E15: Invalid expression: s:git('rev-parse', '--show-prefix')  

Behaviors of :OpenGithubIssue and :OpenGithubPullReq with no arguments

To @rhysd (via #20)

すみません、よく見ずにマージしてしまって本当に悪いのですが、
すでに引数がない場合は別の挙動が割り当てられているのを失念していました…

これらの挙動に関しては、#20 で入れた対応は一旦 revert し、
別の Ex コマンド :OpenGithubIssueOnCursor:OpenGithubPullReqOnCursor を追加する形で対応することを考えています。
これら2つの Ex コマンドに関してなるべく @rhysd さんの希望の挙動にしたいのですが、以下のような挙動で大丈夫でしょうか?

" 引数なしで呼び出すとカーソル下の issue 番号(#xxx)を開く
:OpenGithubIssueOnCursor
" これはエラー(引数は受け付けない)
:OpenGithubIssueOnCursor 123

引数を受け付けるかどうかなどについて @rhysd さんのニーズに合わせて変えていきたいです。

:'<,'>OpenGithubFile opens URL without line-number

':'<,'>OpenGithubFile' opens target file in GitHub.
But the URL is without line-number.

It shows message like below.

opening 'https://github.com/kyoh86/gordon/blob/9fe7952d6d1d0c093300eed487d803eced23b8e5/internal/env/def.go' ... done! (xdg-open)

my env FYI:

:version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Feb 12 2020 03:12:45)
Included patches: 1-246
Compiled by Arch Linux AUR
Huge version with GTK2 GUI.  Features included (+) or not (-):
+acl               +clientserver      +diff              +folding           +libcall           +mouse_gpm         +packages          +rightleft         -tag_old_static    +user_commands     +X11
+arabic            +clipboard         +digraphs          -footer            +linebreak         -mouse_jsbterm     +path_extra        +ruby/dyn          -tag_any_white     +vartabs           -xfontset
+autocmd           +cmdline_compl     +dnd               +fork()            +lispindent        +mouse_netterm     +perl/dyn          +scrollbind        -tcl               +vertsplit         +xim
+autochdir         +cmdline_hist      -ebcdic            +gettext           +listcmds          +mouse_sgr         +persistent_undo   +signs             +termguicolors     +virtualedit       +xpm
-autoservername    +cmdline_info      +emacs_tags        -hangul_input      +localmap          -mouse_sysmouse    +popupwin          +smartindent       +terminal          +visual            +xsmp_interact
+balloon_eval      +comments          +eval              +iconv             +lua/dyn           +mouse_urxvt       +postscript        +sound             +terminfo          +visualextra       +xterm_clipboard
+balloon_eval_term +conceal           +ex_extra          +insert_expand     +menu              +mouse_xterm       +printer           +spell             +termresponse      +viminfo           -xterm_save
+browse            +cryptv            +extra_search      +job               +mksession         +multi_byte        +profile           +startuptime       +textobjects       +vreplace          
++builtin_terms    +cscope            -farsi             +jumplist          +modify_fname      +multi_lang        +python/dyn        +statusline        +textprop          +wildignore        
+byte_offset       +cursorbind        +file_in_path      +keymap            +mouse             -mzscheme          +python3/dyn       -sun_workshop      +timers            +wildmenu          
+channel           +cursorshape       +find_in_path      +lambda            +mouseshape        +netbeans_intg     +quickfix          +syntax            +title             +windows           
+cindent           +dialog_con_gui    +float             +langmap           +mouse_dec         +num64             +reltime           +tag_binary        +toolbar           +writebackup       
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/libffi-3.2.1/include -I/usr/include/harfbuzz -I/usr/include/fribidi -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/atk-1.0 -pthread    -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -D_REENTRANT  -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc   -L. -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.30/core_perl/CORE  -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -L/usr/local/lib -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lharfbuzz -lfontconfig -lfreetype  -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lelf -lnsl    -lcanberra  -lacl -lattr -lgpm -ldl   -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.30/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/perl5/5.30/core_perl/CORE -lperl -lpthread -ldl -lm -lcrypt -lutil -lc        
$ hub --version
git version 2.26.0
hub version 2.14.2
$ uname -rsv
Linux 5.5.13-arch1-1 #1 SMP PREEMPT Wed, 25 Mar 2020 16:04:40 +0000

他の人のレポジトリの参照

設定したgithub.user/レポジトリ名

のURLに行くと思われるのですが、他の人のレポジトリだった場合は現在は想定されてない感じでしょうか?

ブランチ名を元に該当するPull Requestを開く機能

いつも便利に使わせてもらっています。

Githubは https://github.com/<OWNER>/<REPO>/pull/<branch> のようにブランチ名を指定するとPull Requestのページにリダイレクトされるようです。(参考

これを利用してブランチ名からPull Requestページを開けるようになると便利かなと思うのですが、そういった機能を追加してもらう事は可能でしょうか。。?

一応以下のような変更を加える事でサクッと実現はできたのですが、コードの全体感を把握できている訳ではないので適切なコードをどのように作ったら良いかは分かっていません。。ゼヒ機能追加をご検討頂けるとありがたいです。

diff --git a/autoload/openbrowser/github.vim b/autoload/openbrowser/github.vim
index e36da26..6b1695a 100644
--- a/autoload/openbrowser/github.vim
+++ b/autoload/openbrowser/github.vim
@@ -189,6 +189,8 @@ function! s:cmd_open_url(args, type)
     elseif a:type ==# s:TYPE_PULLREQ
         if number !=# ''
             let path = 'pull/' . number
+        elseif get(a:args, 0, '') !=# ''
+            let path = 'pull/' . a:args[0]
         else
             let path = 'pulls'
         endif

How do I set up a key mapping?

i can't work out how to set up a key mapping to open the current file in github.

nmap gh <Plug>(openbrowser-github-file) didn't work…

Default to user.name as user

If a repo has multiple users, it asks me to choose one. But I would like to have one of two default behaviors: Default to the "origin" repo, or default to the repo which contains my git config user.name - I don't want to choose manually.

Open GitHub in a suitable protocol

GitHub Enterprise は組織によっては HTTPS をサポートしない環境で利用されているため、HTTP または HTTPS のどちらかに固定するのではなく、リポジトリによって適切なプロトコルで開いてほしいと思います。

hub browse -u を利用すると、適切に設定されていれば正確な URL が得られるので、個人的には hub を利用するようになると嬉しいです。ただ、HTTPS 固定で困らない方も多いでしょうから、hub が入っている場合には hub を利用し、入っていない場合には HTTPS 固定 (またはオプション指定) といった動作になるのが望ましいかなと思います。

% hub browse -u -- blob/master/README.md
https://github.com/tyru/open-browser-github.vim/blob/master/README.md

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.