diff options
author | Teddy Wing | 2018-04-06 00:56:32 +0200 |
---|---|---|
committer | Teddy Wing | 2018-04-06 00:56:32 +0200 |
commit | 2255d27130b29c578366d6cd0fa41f3af94c1702 (patch) | |
tree | 4fca0e17141b2d57609bce7318703f2969054c92 | |
parent | 920a45031e322d81827f2102ec5847f7479305ad (diff) | |
download | dotvim-2255d27130b29c578366d6cd0fa41f3af94c1702.tar.bz2 |
Add 'github-url' plugin
A rough working implementation of a plugin that generates a GitHub URL
for the current file.
It gets the base URL from the current Git repo's `origin` remote and
uses the current commit SHA. Lines can also be highlighted by passing a
range to the command.
This makes it easier to share a bit of code that I see in the editor
with other people on my team in chat or the issue tracker.
-rw-r--r-- | bundle/github-url/plugin/github_url.vim | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/bundle/github-url/plugin/github_url.vim b/bundle/github-url/plugin/github_url.vim new file mode 100644 index 0000000..a6d8e87 --- /dev/null +++ b/bundle/github-url/plugin/github_url.vim @@ -0,0 +1,26 @@ +" TODO: doc +function! s:BaseRepoURL() + let remote = system('git remote get-url origin') + let base_url = substitute(remote, ':', '/', '') + let base_url = substitute(base_url, '^git@', 'https://', '') + let base_url = substitute(base_url, '.git\n$', '', '') + + return base_url +endfunction + +" TODO: doc +function! s:FileURL(start_line, end_line) + let current_sha = system('git show --format="format:%H"') + let current_sha = substitute(current_sha, '\n$', '', '') + let current_filename = expand('%') + let lines = '' + + if a:start_line && a:end_line + let lines = '#L' . a:start_line . '-L' . a:end_line + endif + + return s:BaseRepoURL() . '/blob/' . current_sha . '/' . current_filename . lines +endfunction + +" echo s:FileURL() +command! -range GitHubFileURL :echo <SID>FileURL(<line1>, <line2>) |