-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
15 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <line1>,<line2>call GitHubURL() |