Skip to content

Commit fa8501e

Browse files
committed
fix: escape paths in open commands, fixes #197
1 parent 28fb314 commit fa8501e

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lua/neo-tree/sources/filesystem/lib/fs_actions.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ M.move_node = function(source, destination, callback)
7676
create_all_parents(dest)
7777
loop.fs_rename(source, dest, function(err)
7878
if err then
79-
log.error("Could not move the files")
79+
log.error("Could not move the files from", source, "to", dest, ":", err)
8080
return
8181
end
8282
vim.schedule(function()
@@ -99,7 +99,7 @@ M.copy_node = function(source, _destination, callback)
9999
create_all_parents(destination)
100100
loop.fs_copyfile(source, destination, function(err)
101101
if err then
102-
log.error("Could not copy the files")
102+
log.error("Could not copy the files from", source, "to", destination, ":", err)
103103
return
104104
end
105105
vim.schedule(function()

lua/neo-tree/utils.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ M.open_file = function(state, path, open_cmd)
305305
end
306306

307307
if M.truthy(path) then
308+
local escaped_path = vim.fn.fnameescape(path)
308309
local events = require("neo-tree.events")
309310
local event_result = events.fire_event(events.FILE_OPEN_REQUESTED, {
310311
state = state,
@@ -316,7 +317,7 @@ M.open_file = function(state, path, open_cmd)
316317
return
317318
end
318319
if state.current_position == "current" then
319-
vim.cmd(open_cmd .. " " .. path)
320+
vim.cmd(open_cmd .. " " .. escaped_path)
320321
else
321322
-- use last window if possible
322323
local suitable_window_found = false
@@ -348,10 +349,10 @@ M.open_file = function(state, path, open_cmd)
348349
-- Neo-tree must be the only window, restore it's status as a sidebar
349350
local winid = vim.api.nvim_get_current_win()
350351
local width = M.get_value(state, "window.width", 40)
351-
vim.cmd("vsplit " .. path)
352+
vim.cmd("vsplit " .. escaped_path)
352353
vim.api.nvim_win_set_width(winid, width)
353354
else
354-
vim.cmd(open_cmd .. " " .. path)
355+
vim.cmd(open_cmd .. " " .. escaped_path)
355356
end
356357
end
357358
events.fire_event(events.FILE_OPENED, path)

0 commit comments

Comments
 (0)