neorg icon indicating copy to clipboard operation
neorg copied to clipboard

Enable using custom commands in `os_open_link`

Open Shaobin-Jiang opened this issue 2 years ago • 0 comments

Issues

  • [x] I have checked existing issues and there are no existing ones with the same request.

Feature description

Pull request #963 added support for using explorer.exe on wsl, which works magnificantly for me when trying to open a web url. However, it is less so when I am trying to open a file:// link.

If I have a link to a file, say C:/file.txt, an url pointing to it in neorg when used on wsl would look like: {file:///mnt/c/file.txt}, which explorer.exe would not recognize.

One solution to this is changing the url to windows-styled ones, like {file:///C:/file.txt}, but this means that completion for file path would not work for me as the path is incomprehensible to the linux system. Also, it might be tricky to open files located in wsl with programs installed on my Windows system.

Currently, I use the wslview command for opening files on wsl (see https://wslutiliti.es/wslu/), and my temporary workaround for replacing the default explorer.exe is alias explorer.exe=wslview. However, it is obvious that this is far from being a nice solution, and it appears to me that a better way is adding support in neorg by allowing the user to specify what command they want to open link.

Help

Yes

Implementation help

I think we might add an vim.g.neorg_open_link_command value and have the user configure that value. Then, in the os_open_link function in lua/neorg/modules/core/esupports/hop/module.lua, we might add something like:

local function os_open_link(link_location)
	local o = {}
	if neorg.configuration.os_info == "windows" then
		o.command = "rundll32.exe"
		o.args = { "url.dll,FileProtocolHandler", link_location }
	else
		if neorg.configuration.os_info == "linux" then
			o.command = "xdg-open"
		elseif neorg.configuration.os_info == "mac" then
			o.command = "open"
		elseif neorg.configuration.os_info == "wsl" then
			o.command = "explorer.exe"
		end
		o.args = { link_location }
	end

	-- Added stuff is here
	if vim.g.neorg_open_link_command ~= nil then
		o.command = vim.g.neorg_open_link_command
	end

	require("plenary.job"):new(o):start()
end

Shaobin-Jiang avatar Aug 08 '23 05:08 Shaobin-Jiang