ruifm / gitlinker.nvim

A lua neovim plugin to generate shareable file permalinks (with line ranges) for several git web frontend hosts. Inspired by tpope/vim-fugitive's :GBrowse
GNU General Public License v3.0
525 stars 44 forks source link

Doesn't work on Windows #68

Closed lopi-py closed 10 months ago

lopi-py commented 1 year ago

It just doesn't work at all, the only thing that "works" is copying the url into the clipboard but doesn't open on browser.

Aditional context

As I said, open in browser just doesn't work because theres not xdg-open on Windows, also links seems broken: image clipboard: https://github.com/lopi-py/test-stuff/blob/a526a59ad58155db43469e0c789fbdfedba76bd4/C:\Users\HP\Downloads\test-stuff\README.md#L3-L3 (yes, including C:\Users...)

I'll try to create a PR on my free time

dstanberry commented 1 year ago
local Job = require "plenary.job"
local command
local args = { url }
if vim.loop.os_uname().sysname == "Darwin" then
  command = "open"
elseif vim.fn.has "win32" or vim.fn.has "wsl" then
  command = "cmd.exe"
  args = { "/c", "start", url }
else
  command = "xdg-open"
end
Job:new({ command = command, args = args }):start()

The above snippet works and is what I use in my personal config. This change seems safe to adopt in the default action_callback.

It seems plenary.nvim has issues with resolving filepaths on Windows, so I added a bit of a hack to the callback:

callbacks = {
  ["github.com"] = function(url_data)
    if has "win32" then
      local git_root = require("gitlinker.git").get_git_root()
      -- use forward slashes only (browser urls don't use backslash char)
      git_root = git_root:gsub("\\", "/")
      url_data.file = url_data.file:gsub("\\", "/")
      -- HACK: trim git root from file to get relative path.. YMMV
      url_data.file = url_data.file:gsub(git_root, "")
      -- trim leading slash
      if url_data.file:sub(1, 1) == "/" then
        url_data.file = url_data.file:sub(2)
      end
    end
    return require("gitlinker.hosts").get_github_type_url(url_data)
  end,
}
linrongbin16 commented 10 months ago

fixed in https://github.com/linrongbin16/gitlinker.nvim