M.reset = function(opts)
opts = opts or {}
+ -- make sure that both windows exist
if not (M.left_id and M.right_id) then
-- remember window id of left pane for later
M.left_id = vim.api.nvim_get_current_win()
M.right_id = vim.api.nvim_open_win(0, true, win_config)
end
- if opts.start_explorer then
- local start_explorer = function(win_id, cwd)
+ -- set working directory and start file browser (for each window)
+ do
+ local set_cwd = function(win_id, cwd)
vim.api.nvim_set_current_win(win_id)
- vim.cmd.Explore(cwd)
+
+ if cwd then
+ vim.cmd("cd" ..cwd)
+ else
+ cwd = vim.fn.getcwd()
+ end
+
+ if opts.start_explorer then
+ vim.cmd.Explore(cwd)
+ end
end
- local cwd = vim.fn.getcwd()
- start_explorer(M.left_id, cwd)
- start_explorer(M.right_id, cwd)
+ set_cwd(M.left_id, opts.path)
+ set_cwd(M.right_id, opts.path)
end
end
-- close all buffers
vim.cmd("bufdo bdelete")
+ -- determine new directory
local selection = action_state.get_selected_entry()
local entry = selection.value
- -- change the current directory
- vim.cmd("cd" ..entry.path)
- while vim.fn.getcwd() ~= entry.path do
- print("waiting...")
- end
-
-- split window
local vsplit = require("snippets.vsplit")
- vsplit.reset{ start_explorer = true }
+ vsplit.reset{ path = entry.path, start_explorer = true }
end)
return true
end