Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable using custom commands in os_open_link #1017

Open
1 task done
Shaobin-Jiang opened this issue Aug 8, 2023 · 0 comments
Open
1 task done

Enable using custom commands in os_open_link #1017

Shaobin-Jiang opened this issue Aug 8, 2023 · 0 comments
Labels
feature Issues related to feature proposals. Please attach a module.

Comments

@Shaobin-Jiang
Copy link

Shaobin-Jiang commented Aug 8, 2023

Issues

  • 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 Shaobin-Jiang added the feature Issues related to feature proposals. Please attach a module. label Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Issues related to feature proposals. Please attach a module.
Projects
None yet
Development

No branches or pull requests

1 participant