@@ -4,7 +4,7 @@ local utils = require "nvim-tree.utils"
44local M = {}
55
66--- @param node Node
7- function M . fn (node )
7+ local function user (node )
88 if # M .config .system_open .cmd == 0 then
99 require (" nvim-tree.utils" ).notify .warn " Cannot open file with system application. Unrecognized platform."
1010 return
@@ -49,20 +49,43 @@ function M.fn(node)
4949 vim .loop .unref (process .handle )
5050end
5151
52+ --- @param node Node
53+ local function native (node )
54+ local path = node .link_to or node .absolute_path
55+
56+ local _ , err = vim .ui .open (path )
57+
58+ -- err only provided on opener executable not found; path not useful in that case
59+ if err then
60+ notify .warn (err )
61+ end
62+ end
63+
64+ --- @param node Node
65+ function M .fn (node )
66+ M .open (node )
67+ end
68+
69+ -- TODO always use native once 0.10 is the minimum neovim version
5270function M .setup (opts )
5371 M .config = {}
5472 M .config .system_open = opts .system_open or {}
5573
56- if # M .config .system_open .cmd == 0 then
57- if utils .is_windows then
58- M .config .system_open = {
59- cmd = " cmd" ,
60- args = { " /c" , " start" , ' ""' },
61- }
62- elseif utils .is_macos then
63- M .config .system_open .cmd = " open"
64- elseif utils .is_unix then
65- M .config .system_open .cmd = " xdg-open"
74+ if vim .fn .has " nvim-0.10" == 1 and # M .config .system_open .cmd == 0 then
75+ M .open = native
76+ else
77+ M .open = user
78+ if # M .config .system_open .cmd == 0 then
79+ if utils .is_windows then
80+ M .config .system_open = {
81+ cmd = " cmd" ,
82+ args = { " /c" , " start" , ' ""' },
83+ }
84+ elseif utils .is_macos then
85+ M .config .system_open .cmd = " open"
86+ elseif utils .is_unix then
87+ M .config .system_open .cmd = " xdg-open"
88+ end
6689 end
6790 end
6891end
0 commit comments