From b8607965090cbbfafcdfc9df25be8a975b330504 Mon Sep 17 00:00:00 2001 From: Paul Gross Date: Wed, 31 Jan 2018 21:15:00 -0800 Subject: [PATCH] Add GitHubURL function and command. --- plugin/github-url.vim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 plugin/github-url.vim diff --git a/plugin/github-url.vim b/plugin/github-url.vim new file mode 100644 index 0000000..cfdce72 --- /dev/null +++ b/plugin/github-url.vim @@ -0,0 +1,15 @@ +if exists("g:loaded_github_url") || &cp + finish +endif +let g:loaded_github_url = 1 + +function! GitHubURL() range + let branch = systemlist("git name-rev --name-only HEAD")[0] + let remote = systemlist("git config branch." . branch . ".remote")[0] + let repo = systemlist("git config --get remote." . remote . ".url | sed 's/\.git$//' | sed 's_^git@\\(.*\\):_https://\\1/_' | sed 's_^git://_https://_'")[0] + let revision = systemlist("git rev-parse HEAD")[0] + let path = systemlist("git ls-files --full-name " . @%)[0] + let url = repo . "/blob/" . revision . "/" . path . "#L" . a:firstline . "-L" . a:lastline + echomsg url +endfunction +command! -range GitHubURL ,call GitHubURL()