@@ -34,29 +34,25 @@ function M.githubUrl(what)
3434 local pathInRepoEncoded = pathInRepo :gsub (" %s+" , " %%20" )
3535
3636 local repo = M .getGithubRemote ()
37- if not repo then return end
37+ if not repo then return end -- not on github
3838 local hash = u .syncShellCmd { " git" , " rev-parse" , " HEAD" }
39- local branch = u .syncShellCmd { " git" , " branch" , " --show-current" }
40- -- if on branch, uses branch, if detached HEAD, falls back to HEAD's hash
41- if branch == " " then branch = hash end
42-
43- local mode = vim .fn .mode ()
4439 local url = " https://github.com/" .. repo
40+ local location = " "
4541
46- if what == " file" and mode == " n" then
47- url = url .. (" /blob/%s/%s" ):format (hash , pathInRepoEncoded )
48- elseif what == " file" and mode :find (" [Vv]" ) then
42+ local mode = vim .fn .mode ()
43+ if what == " file" and mode :find (" [Vv]" ) then
4944 vim .cmd .normal { mode , bang = true } -- leave visual mode, so marks are set
5045 local startLn = vim .api .nvim_buf_get_mark (0 , " <" )[1 ]
5146 local endLn = vim .api .nvim_buf_get_mark (0 , " >" )[1 ]
52- local location
5347 if startLn == endLn then -- one-line-selection
54- location = " #L" .. tostring ( startLn )
48+ location = " #L" .. startLn
5549 elseif startLn < endLn then
56- location = " #L" .. tostring ( startLn ) .. " -L" .. tostring ( endLn )
50+ location = " #L" .. startLn .. " -L" .. endLn
5751 else
58- location = " #L" .. tostring ( endLn ) .. " -L" .. tostring ( startLn )
52+ location = " #L" .. endLn .. " -L" .. startLn
5953 end
54+ end
55+ if what == " file" then
6056 url = url .. (" /blob/%s/%s%s" ):format (hash , pathInRepoEncoded , location )
6157 end
6258
0 commit comments