28 lines
859 B
Lua
28 lines
859 B
Lua
local M = {}
|
|
|
|
function M.smart_open()
|
|
local bufname = vim.api.nvim_buf_get_name(0)
|
|
local is_real_file = vim.fn.filereadable(bufname) == 1
|
|
local cwd = vim.fn.getcwd()
|
|
|
|
local target_path = "~"
|
|
|
|
if is_real_file then
|
|
target_path = vim.fn.fnamemodify(bufname, ":p:h")
|
|
vim.cmd("Neotree toggle position=left reveal_file=" .. target_path)
|
|
elseif bufname ~= "" then
|
|
-- buffer avec un nom mais fichier inexistant (ex: nouveau buffer)
|
|
target_path = "~"
|
|
vim.cmd("Neotree toggle position=right reveal_force_cwd reveal_file=" .. target_path)
|
|
elseif vim.bo.filetype == "ministarter" then
|
|
-- buffer mini.starter
|
|
target_path = "~"
|
|
vim.cmd("Neotree toggle reveal=true position=float dir=" .. target_path)
|
|
end
|
|
|
|
-- Appel de Neotree avec le bon dossier
|
|
-- vim.cmd("Neotree toggle reveal=true dir=" .. target_path)
|
|
end
|
|
|
|
return M
|