aboutsummaryrefslogtreecommitdiffstats
path: root/bundle/github-url/autoload
diff options
context:
space:
mode:
Diffstat (limited to 'bundle/github-url/autoload')
-rw-r--r--bundle/github-url/autoload/github_url.vim14
1 files changed, 12 insertions, 2 deletions
diff --git a/bundle/github-url/autoload/github_url.vim b/bundle/github-url/autoload/github_url.vim
index e090681..713ba89 100644
--- a/bundle/github-url/autoload/github_url.vim
+++ b/bundle/github-url/autoload/github_url.vim
@@ -16,7 +16,7 @@ endfunction
function! s:FileURL(include_lines, start_line, end_line)
let current_sha = system('git show --no-patch --format="format:%H"')
let current_sha = substitute(current_sha, '\n$', '', '')
- let current_filename = expand('%')
+ let current_filename = s:FilePathRelativeToRepoRoot()
let lines = ''
if a:include_lines
@@ -27,7 +27,7 @@ function! s:FileURL(include_lines, start_line, end_line)
endif
endif
- return s:BaseRepoURL() . '/blob/' . current_sha . '/' . current_filename . lines
+ return s:BaseRepoURL() . '/blob/' . current_sha . current_filename . lines
endfunction
" Copy the GitHub URL to the clipboard and echo it to the command line.
@@ -37,3 +37,13 @@ function! github_url#GitHubURL(include_lines, start_line, end_line)
call system('pbcopy', url)
echo url
endfunction
+
+" Get the path of the current file relative to the repository root. Gives us
+" the correct path to the file even if `:pwd` is below the Git root. The
+" returned path begins with a `/`.
+function! s:FilePathRelativeToRepoRoot()
+ let repo_root = system('git rev-parse --show-toplevel')[:-2]
+ let current_file_absolute = expand('%:p')
+
+ return substitute(current_file_absolute, repo_root, '', '')
+endfunction