chore: add stylua to format the codebase, and run on CI (#1055)
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
local a = vim.api
|
||||
local utils = require'nvim-tree.utils'
|
||||
local utils = require "nvim-tree.utils"
|
||||
|
||||
local M = {
|
||||
current_tab = a.nvim_get_current_tabpage(),
|
||||
options = {
|
||||
global = false,
|
||||
change_cwd = true,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
function M.fn(name, with_open)
|
||||
if not TreeExplorer then return end
|
||||
if not TreeExplorer then
|
||||
return
|
||||
end
|
||||
|
||||
local foldername = name == '..' and vim.fn.fnamemodify(utils.path_remove_trailing(TreeExplorer.cwd), ':h') or name
|
||||
local foldername = name == ".." and vim.fn.fnamemodify(utils.path_remove_trailing(TreeExplorer.cwd), ":h") or name
|
||||
local no_cwd_change = vim.fn.expand(foldername) == TreeExplorer.cwd
|
||||
local new_tab = a.nvim_get_current_tabpage()
|
||||
local is_window = (vim.v.event.scope == "window" or vim.v.event.changed_window) and new_tab == M.current_tab
|
||||
@@ -26,16 +28,16 @@ end
|
||||
function M.force_dirchange(foldername, with_open)
|
||||
if M.options.change_cwd and vim.tbl_isempty(vim.v.event) then
|
||||
if M.options.global then
|
||||
vim.cmd('cd '..vim.fn.fnameescape(foldername))
|
||||
vim.cmd("cd " .. vim.fn.fnameescape(foldername))
|
||||
else
|
||||
vim.cmd('lcd '..vim.fn.fnameescape(foldername))
|
||||
vim.cmd("lcd " .. vim.fn.fnameescape(foldername))
|
||||
end
|
||||
end
|
||||
require'nvim-tree.lib'.init(foldername)
|
||||
require("nvim-tree.lib").init(foldername)
|
||||
if with_open then
|
||||
require"nvim-tree.lib".open()
|
||||
require("nvim-tree.lib").open()
|
||||
else
|
||||
require"nvim-tree.renderer".draw()
|
||||
require("nvim-tree.renderer").draw()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local renderer = require"nvim-tree.renderer"
|
||||
local renderer = require "nvim-tree.renderer"
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
local a = vim.api
|
||||
local uv = vim.loop
|
||||
|
||||
local lib = require'nvim-tree.lib'
|
||||
local utils = require'nvim-tree.utils'
|
||||
local lib = require "nvim-tree.lib"
|
||||
local utils = require "nvim-tree.utils"
|
||||
|
||||
local M = {}
|
||||
|
||||
local clipboard = {
|
||||
move = {},
|
||||
copy = {}
|
||||
copy = {},
|
||||
}
|
||||
|
||||
local function do_copy(source, destination)
|
||||
local source_stats = uv.fs_stat(source)
|
||||
|
||||
if source_stats and source_stats.type == 'file' then
|
||||
if source_stats and source_stats.type == "file" then
|
||||
return uv.fs_copyfile(source, destination)
|
||||
end
|
||||
|
||||
local handle = uv.fs_scandir(source)
|
||||
|
||||
if type(handle) == 'string' then
|
||||
if type(handle) == "string" then
|
||||
return false, handle
|
||||
end
|
||||
|
||||
@@ -28,12 +28,16 @@ local function do_copy(source, destination)
|
||||
|
||||
while true do
|
||||
local name, _ = uv.fs_scandir_next(handle)
|
||||
if not name then break end
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
|
||||
local new_name = utils.path_join({source, name})
|
||||
local new_destination = utils.path_join({destination, name})
|
||||
local new_name = utils.path_join { source, name }
|
||||
local new_destination = utils.path_join { destination, name }
|
||||
local success, msg = do_copy(new_name, new_destination)
|
||||
if not success then return success, msg end
|
||||
if not success then
|
||||
return success, msg
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
@@ -45,37 +49,39 @@ local function do_single_paste(source, dest, action_type, action_fn)
|
||||
local should_rename = false
|
||||
|
||||
if dest_stats then
|
||||
print(dest..' already exists. Overwrite? y/n/r(ename)')
|
||||
print(dest .. " already exists. Overwrite? y/n/r(ename)")
|
||||
local ans = utils.get_user_input_char()
|
||||
utils.clear_prompt()
|
||||
should_process = ans:match('^y')
|
||||
should_rename = ans:match('^r')
|
||||
should_process = ans:match "^y"
|
||||
should_rename = ans:match "^r"
|
||||
end
|
||||
|
||||
if should_rename then
|
||||
local new_dest = vim.fn.input('New name: ', dest)
|
||||
local new_dest = vim.fn.input("New name: ", dest)
|
||||
return do_single_paste(source, new_dest, action_type, action_fn)
|
||||
end
|
||||
|
||||
if should_process then
|
||||
local success, errmsg = action_fn(source, dest)
|
||||
if not success then
|
||||
a.nvim_err_writeln('Could not '..action_type..' '..source..' - '..errmsg)
|
||||
a.nvim_err_writeln("Could not " .. action_type .. " " .. source .. " - " .. errmsg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function add_to_clipboard(node, clip)
|
||||
if node.name == '..' then return end
|
||||
if node.name == ".." then
|
||||
return
|
||||
end
|
||||
|
||||
for idx, _node in ipairs(clip) do
|
||||
if _node.absolute_path == node.absolute_path then
|
||||
table.remove(clip, idx)
|
||||
return a.nvim_out_write(node.absolute_path..' removed to clipboard.\n')
|
||||
return a.nvim_out_write(node.absolute_path .. " removed to clipboard.\n")
|
||||
end
|
||||
end
|
||||
table.insert(clip, node)
|
||||
a.nvim_out_write(node.absolute_path..' added to clipboard.\n')
|
||||
a.nvim_out_write(node.absolute_path .. " added to clipboard.\n")
|
||||
end
|
||||
|
||||
function M.copy(node)
|
||||
@@ -88,27 +94,31 @@ end
|
||||
|
||||
local function do_paste(node, action_type, action_fn)
|
||||
node = lib.get_last_group_node(node)
|
||||
if node.name == '..' then return end
|
||||
if node.name == ".." then
|
||||
return
|
||||
end
|
||||
local clip = clipboard[action_type]
|
||||
if #clip == 0 then return end
|
||||
if #clip == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local destination = node.absolute_path
|
||||
local stats = uv.fs_stat(destination)
|
||||
local is_dir = stats and stats.type == 'directory'
|
||||
local is_dir = stats and stats.type == "directory"
|
||||
|
||||
if not is_dir then
|
||||
destination = vim.fn.fnamemodify(destination, ':p:h')
|
||||
destination = vim.fn.fnamemodify(destination, ":p:h")
|
||||
elseif not node.open then
|
||||
destination = vim.fn.fnamemodify(destination, ':p:h:h')
|
||||
destination = vim.fn.fnamemodify(destination, ":p:h:h")
|
||||
end
|
||||
|
||||
for _, _node in ipairs(clip) do
|
||||
local dest = utils.path_join({destination, _node.name })
|
||||
local dest = utils.path_join { destination, _node.name }
|
||||
do_single_paste(_node.absolute_path, dest, action_type, action_fn)
|
||||
end
|
||||
|
||||
clipboard[action_type] = {}
|
||||
return require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
return require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
end
|
||||
|
||||
local function do_cut(source, destination)
|
||||
@@ -122,34 +132,34 @@ end
|
||||
|
||||
function M.paste(node)
|
||||
if clipboard.move[1] ~= nil then
|
||||
return do_paste(node, 'move', do_cut)
|
||||
return do_paste(node, "move", do_cut)
|
||||
end
|
||||
|
||||
return do_paste(node, 'copy', do_copy)
|
||||
return do_paste(node, "copy", do_copy)
|
||||
end
|
||||
|
||||
function M.print_clipboard()
|
||||
local content = {}
|
||||
if #clipboard.move > 0 then
|
||||
table.insert(content, 'Cut')
|
||||
table.insert(content, "Cut")
|
||||
for _, item in pairs(clipboard.move) do
|
||||
table.insert(content, ' * '..item.absolute_path)
|
||||
table.insert(content, " * " .. item.absolute_path)
|
||||
end
|
||||
end
|
||||
if #clipboard.copy > 0 then
|
||||
table.insert(content, 'Copy')
|
||||
table.insert(content, "Copy")
|
||||
for _, item in pairs(clipboard.copy) do
|
||||
table.insert(content, ' * '..item.absolute_path)
|
||||
table.insert(content, " * " .. item.absolute_path)
|
||||
end
|
||||
end
|
||||
|
||||
return a.nvim_out_write(table.concat(content, '\n')..'\n')
|
||||
return a.nvim_out_write(table.concat(content, "\n") .. "\n")
|
||||
end
|
||||
|
||||
local function copy_to_clipboard(content)
|
||||
vim.fn.setreg('+', content)
|
||||
vim.fn.setreg("+", content)
|
||||
vim.fn.setreg('"', content)
|
||||
return a.nvim_out_write(string.format('Copied %s to system clipboard! \n', content))
|
||||
return a.nvim_out_write(string.format("Copied %s to system clipboard! \n", content))
|
||||
end
|
||||
|
||||
function M.copy_filename(node)
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
local a = vim.api
|
||||
local uv = vim.loop
|
||||
|
||||
local utils = require'nvim-tree.utils'
|
||||
local events = require'nvim-tree.events'
|
||||
local lib = require'nvim-tree.lib'
|
||||
local utils = require "nvim-tree.utils"
|
||||
local events = require "nvim-tree.events"
|
||||
local lib = require "nvim-tree.lib"
|
||||
|
||||
local M = {}
|
||||
|
||||
local function focus_file(file)
|
||||
local _, i = utils.find_node(
|
||||
TreeExplorer.nodes,
|
||||
function(node) return node.absolute_path == file end
|
||||
)
|
||||
require'nvim-tree.view'.set_cursor({i+1, 1})
|
||||
local _, i = utils.find_node(TreeExplorer.nodes, function(node)
|
||||
return node.absolute_path == file
|
||||
end)
|
||||
require("nvim-tree.view").set_cursor { i + 1, 1 }
|
||||
end
|
||||
|
||||
local function create_file(file)
|
||||
if utils.file_exists(file) then
|
||||
print(file..' already exists. Overwrite? y/n')
|
||||
print(file .. " already exists. Overwrite? y/n")
|
||||
local ans = utils.get_user_input_char()
|
||||
utils.clear_prompt()
|
||||
if ans ~= "y" then
|
||||
@@ -26,7 +25,7 @@ local function create_file(file)
|
||||
end
|
||||
local ok, fd = pcall(uv.fs_open, file, "w", 420)
|
||||
if not ok then
|
||||
a.nvim_err_writeln('Couldn\'t create file '..file)
|
||||
a.nvim_err_writeln("Couldn't create file " .. file)
|
||||
return
|
||||
end
|
||||
uv.fs_close(fd)
|
||||
@@ -46,20 +45,22 @@ local function get_containing_folder(node)
|
||||
if node.nodes ~= nil and is_open then
|
||||
return utils.path_add_trailing(node.absolute_path)
|
||||
end
|
||||
local node_name_size = #(node.name or '')
|
||||
return node.absolute_path:sub(0, - node_name_size - 1)
|
||||
local node_name_size = #(node.name or "")
|
||||
return node.absolute_path:sub(0, -node_name_size - 1)
|
||||
end
|
||||
|
||||
local function get_input(containing_folder)
|
||||
local ans = vim.fn.input('Create file ', containing_folder)
|
||||
local ans = vim.fn.input("Create file ", containing_folder)
|
||||
utils.clear_prompt()
|
||||
if not ans or #ans == 0 or utils.file_exists(ans) then return end
|
||||
if not ans or #ans == 0 or utils.file_exists(ans) then
|
||||
return
|
||||
end
|
||||
return ans
|
||||
end
|
||||
|
||||
function M.fn(node)
|
||||
node = lib.get_last_group_node(node)
|
||||
if node.name == '..' then
|
||||
if node.name == ".." then
|
||||
node = {
|
||||
absolute_path = TreeExplorer.cwd,
|
||||
nodes = TreeExplorer.nodes,
|
||||
@@ -69,12 +70,14 @@ function M.fn(node)
|
||||
|
||||
local containing_folder = get_containing_folder(node)
|
||||
local file = get_input(containing_folder)
|
||||
if not file then return end
|
||||
if not file then
|
||||
return
|
||||
end
|
||||
|
||||
-- create a folder for each path element if the folder does not exist
|
||||
-- if the answer ends with a /, create a file for the last path element
|
||||
local is_last_path_file = not file:match(utils.path_separator..'$')
|
||||
local path_to_create = ''
|
||||
local is_last_path_file = not file:match(utils.path_separator .. "$")
|
||||
local path_to_create = ""
|
||||
local idx = 0
|
||||
|
||||
local num_nodes = get_num_nodes(utils.path_split(utils.path_remove_trailing(file)))
|
||||
@@ -82,27 +85,27 @@ function M.fn(node)
|
||||
for path in utils.path_split(file) do
|
||||
idx = idx + 1
|
||||
local p = utils.path_remove_trailing(path)
|
||||
if #path_to_create == 0 and vim.fn.has('win32') == 1 then
|
||||
path_to_create = utils.path_join({p, path_to_create})
|
||||
if #path_to_create == 0 and vim.fn.has "win32" == 1 then
|
||||
path_to_create = utils.path_join { p, path_to_create }
|
||||
else
|
||||
path_to_create = utils.path_join({path_to_create, p})
|
||||
path_to_create = utils.path_join { path_to_create, p }
|
||||
end
|
||||
if is_last_path_file and idx == num_nodes then
|
||||
create_file(path_to_create)
|
||||
elseif not utils.file_exists(path_to_create) then
|
||||
local success = uv.fs_mkdir(path_to_create, 493)
|
||||
if not success then
|
||||
a.nvim_err_writeln('Could not create folder '..path_to_create)
|
||||
a.nvim_err_writeln("Could not create folder " .. path_to_create)
|
||||
is_error = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not is_error then
|
||||
a.nvim_out_write(file..' was properly created\n')
|
||||
a.nvim_out_write(file .. " was properly created\n")
|
||||
end
|
||||
events._dispatch_folder_created(file)
|
||||
require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
focus_file(file)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
local utils = require'nvim-tree.utils'
|
||||
local utils = require "nvim-tree.utils"
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.fn(node)
|
||||
if not node or node.name == ".." then
|
||||
return require'nvim-tree.actions.change-dir'.fn('..')
|
||||
return require("nvim-tree.actions.change-dir").fn ".."
|
||||
else
|
||||
local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(TreeExplorer.cwd), ':h')
|
||||
require'nvim-tree.actions.change-dir'.fn(newdir)
|
||||
return require"nvim-tree.actions.find-file".fn(node.absolute_path)
|
||||
local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(TreeExplorer.cwd), ":h")
|
||||
require("nvim-tree.actions.change-dir").fn(newdir)
|
||||
return require("nvim-tree.actions.find-file").fn(node.absolute_path)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
local utils = require'nvim-tree.utils'
|
||||
local utils = require "nvim-tree.utils"
|
||||
local a = vim.api
|
||||
|
||||
local M = {}
|
||||
|
||||
local function get_formatted_lines(node)
|
||||
local stats = node.fs_stat
|
||||
local fpath = ' fullpath: ' .. node.absolute_path
|
||||
local created_at = ' created: ' .. os.date("%x %X", stats.birthtime.sec)
|
||||
local modified_at = ' modified: ' .. os.date("%x %X", stats.mtime.sec)
|
||||
local accessed_at = ' accessed: ' .. os.date("%x %X", stats.atime.sec)
|
||||
local size = ' size: ' .. utils.format_bytes(stats.size)
|
||||
local fpath = " fullpath: " .. node.absolute_path
|
||||
local created_at = " created: " .. os.date("%x %X", stats.birthtime.sec)
|
||||
local modified_at = " modified: " .. os.date("%x %X", stats.mtime.sec)
|
||||
local accessed_at = " accessed: " .. os.date("%x %X", stats.atime.sec)
|
||||
local size = " size: " .. utils.format_bytes(stats.size)
|
||||
|
||||
return {
|
||||
fpath,
|
||||
@@ -25,20 +25,22 @@ local current_popup = nil
|
||||
local function setup_window(node)
|
||||
local lines = get_formatted_lines(node)
|
||||
|
||||
local max_width = vim.fn.max(vim.tbl_map(function(n) return #n end, lines))
|
||||
local max_width = vim.fn.max(vim.tbl_map(function(n)
|
||||
return #n
|
||||
end, lines))
|
||||
local winnr = a.nvim_open_win(0, false, {
|
||||
col = 1,
|
||||
row = 1,
|
||||
relative = "cursor",
|
||||
width = max_width + 1,
|
||||
height = #lines,
|
||||
border = 'shadow',
|
||||
border = "shadow",
|
||||
noautocmd = true,
|
||||
style = 'minimal'
|
||||
style = "minimal",
|
||||
})
|
||||
current_popup = {
|
||||
winnr = winnr,
|
||||
file_path = node.absolute_path
|
||||
file_path = node.absolute_path,
|
||||
}
|
||||
local bufnr = a.nvim_create_buf(false, true)
|
||||
a.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
local view = require'nvim-tree.view'
|
||||
local utils = require'nvim-tree.utils'
|
||||
local renderer = require"nvim-tree.renderer"
|
||||
local view = require "nvim-tree.view"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local renderer = require "nvim-tree.renderer"
|
||||
|
||||
local M = {}
|
||||
|
||||
local function get_index_offset()
|
||||
local hide_root_folder = view.View.hide_root_folder
|
||||
if TreeExplorer.cwd == '/' or hide_root_folder then
|
||||
if TreeExplorer.cwd == "/" or hide_root_folder then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
@@ -16,7 +16,9 @@ end
|
||||
local running = {}
|
||||
|
||||
function M.fn(fname)
|
||||
if running[fname] or not TreeExplorer then return end
|
||||
if running[fname] or not TreeExplorer then
|
||||
return
|
||||
end
|
||||
running[fname] = true
|
||||
|
||||
local i = get_index_offset()
|
||||
@@ -29,7 +31,7 @@ function M.fn(fname)
|
||||
return i
|
||||
end
|
||||
|
||||
local path_matches = node.nodes and vim.startswith(fname, node.absolute_path..utils.path_separator)
|
||||
local path_matches = node.nodes and vim.startswith(fname, node.absolute_path .. utils.path_separator)
|
||||
if path_matches then
|
||||
if not node.open then
|
||||
node.open = true
|
||||
@@ -43,7 +45,7 @@ function M.fn(fname)
|
||||
if iterate_nodes(node.nodes) ~= nil then
|
||||
return i
|
||||
end
|
||||
-- mandatory to iterate i
|
||||
-- mandatory to iterate i
|
||||
elseif node.open then
|
||||
iterate_nodes(node.nodes)
|
||||
end
|
||||
@@ -55,7 +57,7 @@ function M.fn(fname)
|
||||
renderer.draw()
|
||||
end
|
||||
if index and view.is_visible() then
|
||||
view.set_cursor({index, 0})
|
||||
view.set_cursor { index, 0 }
|
||||
end
|
||||
running[fname] = false
|
||||
end
|
||||
|
||||
@@ -1,124 +1,130 @@
|
||||
local a = vim.api
|
||||
|
||||
local lib = require'nvim-tree.lib'
|
||||
local view = require'nvim-tree.view'
|
||||
local util = require'nvim-tree.utils'
|
||||
local nvim_tree_callback = require'nvim-tree.config'.nvim_tree_callback
|
||||
local lib = require "nvim-tree.lib"
|
||||
local view = require "nvim-tree.view"
|
||||
local util = require "nvim-tree.utils"
|
||||
local nvim_tree_callback = require("nvim-tree.config").nvim_tree_callback
|
||||
|
||||
local M = {
|
||||
mappings = {
|
||||
{ key = {"<CR>", "o", "<2-LeftMouse>"}, action = "edit" },
|
||||
{ key = "<C-e>", action = "edit_in_place" },
|
||||
{ key = "O", action = "edit_no_picker" },
|
||||
{ key = {"<2-RightMouse>", "<C-]>"}, action = "cd" },
|
||||
{ key = "<C-v>", action = "vsplit" },
|
||||
{ key = "<C-x>", action = "split"},
|
||||
{ key = "<C-t>", action = "tabnew" },
|
||||
{ key = "<", action = "prev_sibling" },
|
||||
{ key = ">", action = "next_sibling" },
|
||||
{ key = "P", action = "parent_node" },
|
||||
{ key = "<BS>", action = "close_node"},
|
||||
{ key = "<Tab>", action = "preview" },
|
||||
{ key = "K", action = "first_sibling" },
|
||||
{ key = "J", action = "last_sibling" },
|
||||
{ key = "I", action = "toggle_ignored" },
|
||||
{ key = "H", action = "toggle_dotfiles" },
|
||||
{ key = "R", action = "refresh" },
|
||||
{ key = "a", action = "create" },
|
||||
{ key = "d", action = "remove" },
|
||||
{ key = "D", action = "trash"},
|
||||
{ key = "r", action = "rename" },
|
||||
{ key = "<C-r>", action = "full_rename" },
|
||||
{ key = "x", action = "cut" },
|
||||
{ key = "c", action = "copy"},
|
||||
{ key = "p", action = "paste" },
|
||||
{ key = "y", action = "copy_name" },
|
||||
{ key = "Y", action = "copy_path" },
|
||||
{ key = "gy", action = "copy_absolute_path" },
|
||||
{ key = "[c", action = "prev_git_item" },
|
||||
{ key = "]c", action = "next_git_item" },
|
||||
{ key = "-", action = "dir_up" },
|
||||
{ key = "s", action = "system_open" },
|
||||
{ key = "q", action = "close"},
|
||||
{ key = "g?", action = "toggle_help" },
|
||||
{ key = 'W', action = "collapse_all" },
|
||||
{ key = "S", action = "search_node" },
|
||||
{ key = ".", action = "run_file_command" },
|
||||
{ key = "<C-k>", action = "toggle_file_info" }
|
||||
{ key = { "<CR>", "o", "<2-LeftMouse>" }, action = "edit" },
|
||||
{ key = "<C-e>", action = "edit_in_place" },
|
||||
{ key = "O", action = "edit_no_picker" },
|
||||
{ key = { "<2-RightMouse>", "<C-]>" }, action = "cd" },
|
||||
{ key = "<C-v>", action = "vsplit" },
|
||||
{ key = "<C-x>", action = "split" },
|
||||
{ key = "<C-t>", action = "tabnew" },
|
||||
{ key = "<", action = "prev_sibling" },
|
||||
{ key = ">", action = "next_sibling" },
|
||||
{ key = "P", action = "parent_node" },
|
||||
{ key = "<BS>", action = "close_node" },
|
||||
{ key = "<Tab>", action = "preview" },
|
||||
{ key = "K", action = "first_sibling" },
|
||||
{ key = "J", action = "last_sibling" },
|
||||
{ key = "I", action = "toggle_ignored" },
|
||||
{ key = "H", action = "toggle_dotfiles" },
|
||||
{ key = "R", action = "refresh" },
|
||||
{ key = "a", action = "create" },
|
||||
{ key = "d", action = "remove" },
|
||||
{ key = "D", action = "trash" },
|
||||
{ key = "r", action = "rename" },
|
||||
{ key = "<C-r>", action = "full_rename" },
|
||||
{ key = "x", action = "cut" },
|
||||
{ key = "c", action = "copy" },
|
||||
{ key = "p", action = "paste" },
|
||||
{ key = "y", action = "copy_name" },
|
||||
{ key = "Y", action = "copy_path" },
|
||||
{ key = "gy", action = "copy_absolute_path" },
|
||||
{ key = "[c", action = "prev_git_item" },
|
||||
{ key = "]c", action = "next_git_item" },
|
||||
{ key = "-", action = "dir_up" },
|
||||
{ key = "s", action = "system_open" },
|
||||
{ key = "q", action = "close" },
|
||||
{ key = "g?", action = "toggle_help" },
|
||||
{ key = "W", action = "collapse_all" },
|
||||
{ key = "S", action = "search_node" },
|
||||
{ key = ".", action = "run_file_command" },
|
||||
{ key = "<C-k>", action = "toggle_file_info" },
|
||||
},
|
||||
custom_keypress_funcs = {},
|
||||
}
|
||||
|
||||
local keypress_funcs = {
|
||||
close = view.close,
|
||||
close_node = require'nvim-tree.actions.movements'.parent_node(true),
|
||||
collapse_all = require'nvim-tree.actions.collapse-all'.fn,
|
||||
copy_absolute_path = require'nvim-tree.actions.copy-paste'.copy_absolute_path,
|
||||
copy_name = require'nvim-tree.actions.copy-paste'.copy_filename,
|
||||
copy_path = require'nvim-tree.actions.copy-paste'.copy_path,
|
||||
copy = require'nvim-tree.actions.copy-paste'.copy,
|
||||
create = require'nvim-tree.actions.create-file'.fn,
|
||||
cut = require'nvim-tree.actions.copy-paste'.cut,
|
||||
dir_up = require'nvim-tree.actions.dir-up'.fn,
|
||||
first_sibling = require'nvim-tree.actions.movements'.sibling(-math.huge),
|
||||
full_rename = require'nvim-tree.actions.rename-file'.fn(true),
|
||||
last_sibling = require'nvim-tree.actions.movements'.sibling(math.huge),
|
||||
next_git_item = require"nvim-tree.actions.movements".find_git_item('next'),
|
||||
next_sibling = require'nvim-tree.actions.movements'.sibling(1),
|
||||
parent_node = require'nvim-tree.actions.movements'.parent_node(false),
|
||||
paste = require'nvim-tree.actions.copy-paste'.paste,
|
||||
prev_git_item = require"nvim-tree.actions.movements".find_git_item('prev'),
|
||||
prev_sibling = require'nvim-tree.actions.movements'.sibling(-1),
|
||||
refresh = require'nvim-tree.actions.reloaders'.reload_explorer,
|
||||
remove = require'nvim-tree.actions.remove-file'.fn,
|
||||
rename = require'nvim-tree.actions.rename-file'.fn(false),
|
||||
run_file_command = require'nvim-tree.actions.run-command'.run_file_command,
|
||||
search_node = require'nvim-tree.actions.search-node'.fn,
|
||||
toggle_file_info = require'nvim-tree.actions.file-popup'.toggle_file_info,
|
||||
system_open = require'nvim-tree.actions.system-open'.fn,
|
||||
toggle_dotfiles = require"nvim-tree.actions.toggles".dotfiles,
|
||||
toggle_help = require"nvim-tree.actions.toggles".help,
|
||||
toggle_ignored = require"nvim-tree.actions.toggles".ignored,
|
||||
trash = require'nvim-tree.actions.trash'.fn,
|
||||
close_node = require("nvim-tree.actions.movements").parent_node(true),
|
||||
collapse_all = require("nvim-tree.actions.collapse-all").fn,
|
||||
copy_absolute_path = require("nvim-tree.actions.copy-paste").copy_absolute_path,
|
||||
copy_name = require("nvim-tree.actions.copy-paste").copy_filename,
|
||||
copy_path = require("nvim-tree.actions.copy-paste").copy_path,
|
||||
copy = require("nvim-tree.actions.copy-paste").copy,
|
||||
create = require("nvim-tree.actions.create-file").fn,
|
||||
cut = require("nvim-tree.actions.copy-paste").cut,
|
||||
dir_up = require("nvim-tree.actions.dir-up").fn,
|
||||
first_sibling = require("nvim-tree.actions.movements").sibling(-math.huge),
|
||||
full_rename = require("nvim-tree.actions.rename-file").fn(true),
|
||||
last_sibling = require("nvim-tree.actions.movements").sibling(math.huge),
|
||||
next_git_item = require("nvim-tree.actions.movements").find_git_item "next",
|
||||
next_sibling = require("nvim-tree.actions.movements").sibling(1),
|
||||
parent_node = require("nvim-tree.actions.movements").parent_node(false),
|
||||
paste = require("nvim-tree.actions.copy-paste").paste,
|
||||
prev_git_item = require("nvim-tree.actions.movements").find_git_item "prev",
|
||||
prev_sibling = require("nvim-tree.actions.movements").sibling(-1),
|
||||
refresh = require("nvim-tree.actions.reloaders").reload_explorer,
|
||||
remove = require("nvim-tree.actions.remove-file").fn,
|
||||
rename = require("nvim-tree.actions.rename-file").fn(false),
|
||||
run_file_command = require("nvim-tree.actions.run-command").run_file_command,
|
||||
search_node = require("nvim-tree.actions.search-node").fn,
|
||||
toggle_file_info = require("nvim-tree.actions.file-popup").toggle_file_info,
|
||||
system_open = require("nvim-tree.actions.system-open").fn,
|
||||
toggle_dotfiles = require("nvim-tree.actions.toggles").dotfiles,
|
||||
toggle_help = require("nvim-tree.actions.toggles").help,
|
||||
toggle_ignored = require("nvim-tree.actions.toggles").ignored,
|
||||
trash = require("nvim-tree.actions.trash").fn,
|
||||
}
|
||||
|
||||
function M.on_keypress(action)
|
||||
if view.is_help_ui() and action == 'close' then
|
||||
action = 'toggle_help';
|
||||
if view.is_help_ui() and action == "close" then
|
||||
action = "toggle_help"
|
||||
end
|
||||
if view.is_help_ui() and action ~= "toggle_help" then
|
||||
return
|
||||
end
|
||||
if view.is_help_ui() and action ~= 'toggle_help' then return end
|
||||
local node = lib.get_node_at_cursor()
|
||||
if not node then return end
|
||||
if not node then
|
||||
return
|
||||
end
|
||||
|
||||
local custom_function = M.custom_keypress_funcs[action]
|
||||
local default_function = keypress_funcs[action]
|
||||
|
||||
if type(custom_function) == 'function' then
|
||||
if type(custom_function) == "function" then
|
||||
return custom_function(node)
|
||||
elseif default_function then
|
||||
return default_function(node)
|
||||
end
|
||||
|
||||
if action == "preview" then
|
||||
if node.name == '..' then return end
|
||||
if node.name == ".." then
|
||||
return
|
||||
end
|
||||
if not node.nodes then
|
||||
return require'nvim-tree.actions.open-file'.fn('preview', node.absolute_path)
|
||||
return require("nvim-tree.actions.open-file").fn("preview", node.absolute_path)
|
||||
end
|
||||
elseif node.name == ".." then
|
||||
return require'nvim-tree.actions.change-dir'.fn("..")
|
||||
return require("nvim-tree.actions.change-dir").fn ".."
|
||||
elseif action == "cd" then
|
||||
if node.nodes ~= nil then
|
||||
require'nvim-tree.actions.change-dir'.fn(lib.get_last_group_node(node).absolute_path)
|
||||
require("nvim-tree.actions.change-dir").fn(lib.get_last_group_node(node).absolute_path)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if node.link_to and not node.nodes then
|
||||
require'nvim-tree.actions.open-file'.fn(action, node.link_to)
|
||||
require("nvim-tree.actions.open-file").fn(action, node.link_to)
|
||||
elseif node.nodes ~= nil then
|
||||
lib.expand_or_collapse(node)
|
||||
else
|
||||
require'nvim-tree.actions.open-file'.fn(action, node.absolute_path)
|
||||
require("nvim-tree.actions.open-file").fn(action, node.absolute_path)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -127,10 +133,10 @@ function M.apply_mappings(bufnr)
|
||||
local mapping_rhs = b.cb or nvim_tree_callback(b.action)
|
||||
if type(b.key) == "table" then
|
||||
for _, key in pairs(b.key) do
|
||||
a.nvim_buf_set_keymap(bufnr, b.mode or 'n', key, mapping_rhs, { noremap = true, silent = true, nowait = true })
|
||||
a.nvim_buf_set_keymap(bufnr, b.mode or "n", key, mapping_rhs, { noremap = true, silent = true, nowait = true })
|
||||
end
|
||||
elseif mapping_rhs then
|
||||
a.nvim_buf_set_keymap(bufnr, b.mode or 'n', b.key, mapping_rhs, { noremap = true, silent = true, nowait = true })
|
||||
a.nvim_buf_set_keymap(bufnr, b.mode or "n", b.key, mapping_rhs, { noremap = true, silent = true, nowait = true })
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -141,7 +147,7 @@ local function merge_mappings(user_mappings)
|
||||
end
|
||||
|
||||
local function is_empty(s)
|
||||
return s == ''
|
||||
return s == ""
|
||||
end
|
||||
|
||||
local user_keys = {}
|
||||
@@ -166,8 +172,8 @@ local function merge_mappings(user_mappings)
|
||||
if not is_empty(map.action) then
|
||||
M.custom_keypress_funcs[map.action] = map.action_cb
|
||||
else
|
||||
util.warn("action can't be empty if action_cb provided")
|
||||
end
|
||||
util.warn "action can't be empty if action_cb provided"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -209,17 +215,17 @@ end
|
||||
|
||||
local DEFAULT_MAPPING_CONFIG = {
|
||||
custom_only = false,
|
||||
list = {}
|
||||
list = {},
|
||||
}
|
||||
|
||||
function M.setup(opts)
|
||||
require'nvim-tree.actions.system-open'.setup(opts.system_open)
|
||||
require'nvim-tree.actions.trash'.setup(opts.trash)
|
||||
require'nvim-tree.actions.open-file'.setup(opts)
|
||||
require'nvim-tree.actions.change-dir'.setup(opts)
|
||||
require("nvim-tree.actions.system-open").setup(opts.system_open)
|
||||
require("nvim-tree.actions.trash").setup(opts.trash)
|
||||
require("nvim-tree.actions.open-file").setup(opts)
|
||||
require("nvim-tree.actions.change-dir").setup(opts)
|
||||
|
||||
local user_map_config = (opts.view or {}).mappings or {}
|
||||
local options = vim.tbl_deep_extend('force', DEFAULT_MAPPING_CONFIG, user_map_config)
|
||||
local options = vim.tbl_deep_extend("force", DEFAULT_MAPPING_CONFIG, user_map_config)
|
||||
if options.custom_only then
|
||||
M.mappings = copy_mappings(options.list)
|
||||
else
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
local utils = require'nvim-tree.utils'
|
||||
local view = require'nvim-tree.view'
|
||||
local diagnostics = require'nvim-tree.diagnostics'
|
||||
local renderer = require"nvim-tree.renderer"
|
||||
local lib = function() return require'nvim-tree.lib' end
|
||||
local utils = require "nvim-tree.utils"
|
||||
local view = require "nvim-tree.view"
|
||||
local diagnostics = require "nvim-tree.diagnostics"
|
||||
local renderer = require "nvim-tree.renderer"
|
||||
local lib = function()
|
||||
return require "nvim-tree.lib"
|
||||
end
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -10,7 +12,7 @@ local function get_line_from_node(node, find_parent)
|
||||
local node_path = node.absolute_path
|
||||
|
||||
if find_parent then
|
||||
node_path = node.absolute_path:match("(.*)"..utils.path_separator)
|
||||
node_path = node.absolute_path:match("(.*)" .. utils.path_separator)
|
||||
end
|
||||
|
||||
local line = 2
|
||||
@@ -24,17 +26,20 @@ local function get_line_from_node(node, find_parent)
|
||||
line = line + 1
|
||||
if _node.open == true and recursive then
|
||||
local _, child = iter(_node.nodes, recursive)
|
||||
if child ~= nil then return line, child end
|
||||
if child ~= nil then
|
||||
return line, child
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return iter
|
||||
end
|
||||
|
||||
|
||||
function M.parent_node(should_close)
|
||||
return function(node)
|
||||
if node.name == '..' then return end
|
||||
if node.name == ".." then
|
||||
return
|
||||
end
|
||||
|
||||
should_close = should_close or false
|
||||
local altered_tree = false
|
||||
@@ -52,7 +57,7 @@ function M.parent_node(should_close)
|
||||
altered_tree = true
|
||||
end
|
||||
line = view.View.hide_root_folder and line - 1 or line
|
||||
view.set_cursor({line, 0})
|
||||
view.set_cursor { line, 0 }
|
||||
end
|
||||
|
||||
if altered_tree then
|
||||
@@ -64,7 +69,9 @@ end
|
||||
|
||||
function M.sibling(direction)
|
||||
return function(node)
|
||||
if node.name == '..' or not direction then return end
|
||||
if node.name == ".." or not direction then
|
||||
return
|
||||
end
|
||||
|
||||
local iter = get_line_from_node(node, true)
|
||||
local node_path = node.absolute_path
|
||||
@@ -100,7 +107,7 @@ function M.sibling(direction)
|
||||
local target_node = parent.nodes[index]
|
||||
|
||||
line, _ = get_line_from_node(target_node)(TreeExplorer.nodes, true)
|
||||
view.set_cursor({line, 0})
|
||||
view.set_cursor { line, 0 }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -128,17 +135,17 @@ function M.find_git_item(where)
|
||||
end
|
||||
end
|
||||
|
||||
if where == 'prev' then
|
||||
if where == "prev" then
|
||||
if prev then
|
||||
view.set_cursor({prev, 0})
|
||||
view.set_cursor { prev, 0 }
|
||||
end
|
||||
else
|
||||
if cur then
|
||||
if nex then
|
||||
view.set_cursor({nex, 0})
|
||||
view.set_cursor { nex, 0 }
|
||||
end
|
||||
elseif first then
|
||||
view.set_cursor({first, 0})
|
||||
view.set_cursor { first, 0 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
local api = vim.api
|
||||
|
||||
local lib = require'nvim-tree.lib'
|
||||
local utils = require'nvim-tree.utils'
|
||||
local view = require'nvim-tree.view'
|
||||
local lib = require "nvim-tree.lib"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local view = require "nvim-tree.view"
|
||||
|
||||
local M = {
|
||||
quit_on_open = false,
|
||||
@@ -11,24 +11,24 @@ local M = {
|
||||
enable = true,
|
||||
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
|
||||
exclude = {
|
||||
filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame", },
|
||||
buftype = { "nofile", "terminal", "help", },
|
||||
}
|
||||
}
|
||||
filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" },
|
||||
buftype = { "nofile", "terminal", "help" },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
local function get_split_cmd()
|
||||
local side = view.View.side
|
||||
if side == 'right' then
|
||||
return 'aboveleft'
|
||||
if side == "right" then
|
||||
return "aboveleft"
|
||||
end
|
||||
if side == "left" then
|
||||
return 'belowright'
|
||||
return "belowright"
|
||||
end
|
||||
if side == "top" then
|
||||
return 'bot'
|
||||
return "bot"
|
||||
end
|
||||
return 'top'
|
||||
return "top"
|
||||
end
|
||||
|
||||
---Get user to pick a window. Selectable windows are all windows in the current
|
||||
@@ -41,7 +41,7 @@ local function pick_window()
|
||||
local win_ids = api.nvim_tabpage_list_wins(tabpage)
|
||||
local tree_winid = view.get_winnr(tabpage)
|
||||
|
||||
local selectable = vim.tbl_filter(function (id)
|
||||
local selectable = vim.tbl_filter(function(id)
|
||||
local bufid = api.nvim_win_get_buf(id)
|
||||
for option, v in pairs(M.window_picker.exclude) do
|
||||
local ok, option_value = pcall(api.nvim_buf_get_option, bufid, option)
|
||||
@@ -51,14 +51,16 @@ local function pick_window()
|
||||
end
|
||||
|
||||
local win_config = api.nvim_win_get_config(id)
|
||||
return id ~= tree_winid
|
||||
and win_config.focusable
|
||||
and not win_config.external
|
||||
return id ~= tree_winid and win_config.focusable and not win_config.external
|
||||
end, win_ids)
|
||||
|
||||
-- If there are no selectable windows: return. If there's only 1, return it without picking.
|
||||
if #selectable == 0 then return -1 end
|
||||
if #selectable == 1 then return selectable[1] end
|
||||
if #selectable == 0 then
|
||||
return -1
|
||||
end
|
||||
if #selectable == 1 then
|
||||
return selectable[1]
|
||||
end
|
||||
|
||||
local i = 1
|
||||
local win_opts = {}
|
||||
@@ -74,21 +76,21 @@ local function pick_window()
|
||||
|
||||
win_opts[id] = {
|
||||
statusline = ok_status and statusline or "",
|
||||
winhl = ok_hl and winhl or ""
|
||||
winhl = ok_hl and winhl or "",
|
||||
}
|
||||
win_map[char] = id
|
||||
|
||||
api.nvim_win_set_option(id, "statusline", "%=" .. char .. "%=")
|
||||
api.nvim_win_set_option(
|
||||
id, "winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker"
|
||||
)
|
||||
api.nvim_win_set_option(id, "winhl", "StatusLine:NvimTreeWindowPicker,StatusLineNC:NvimTreeWindowPicker")
|
||||
|
||||
i = i + 1
|
||||
if i > #M.window_picker.chars then break end
|
||||
if i > #M.window_picker.chars then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
vim.cmd("redraw")
|
||||
print("Pick window: ")
|
||||
vim.cmd "redraw"
|
||||
print "Pick window: "
|
||||
local _, resp = pcall(utils.get_user_input_char)
|
||||
resp = (resp or ""):upper()
|
||||
utils.clear_prompt()
|
||||
@@ -114,7 +116,7 @@ local function open_file_in_tab(filename)
|
||||
if lib.target_winid > 0 and api.nvim_win_is_valid(lib.target_winid) then
|
||||
api.nvim_set_current_win(lib.target_winid)
|
||||
else
|
||||
vim.cmd("wincmd p")
|
||||
vim.cmd "wincmd p"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -126,13 +128,13 @@ local function open_file_in_tab(filename)
|
||||
|
||||
vim.cmd("edit " .. vim.fn.fnameescape(filename))
|
||||
|
||||
local alt_bufid = vim.fn.bufnr("#")
|
||||
local alt_bufid = vim.fn.bufnr "#"
|
||||
if alt_bufid ~= -1 then
|
||||
api.nvim_set_current_buf(alt_bufid)
|
||||
end
|
||||
|
||||
if not M.quit_on_open then
|
||||
vim.cmd("wincmd p")
|
||||
vim.cmd "wincmd p"
|
||||
end
|
||||
|
||||
vim.cmd("tabe " .. vim.fn.fnameescape(filename))
|
||||
@@ -145,7 +147,7 @@ function M.fn(mode, filename)
|
||||
end
|
||||
|
||||
if mode == "edit_in_place" then
|
||||
require"nvim-tree.view".abandon_current_window()
|
||||
require("nvim-tree.view").abandon_current_window()
|
||||
vim.cmd("edit " .. vim.fn.fnameescape(filename))
|
||||
return
|
||||
end
|
||||
@@ -171,7 +173,9 @@ function M.fn(mode, filename)
|
||||
local found = false
|
||||
for _, id in ipairs(win_ids) do
|
||||
if filename == api.nvim_buf_get_name(api.nvim_win_get_buf(id)) then
|
||||
if mode == "preview" then return end
|
||||
if mode == "preview" then
|
||||
return
|
||||
end
|
||||
found = true
|
||||
api.nvim_set_current_win(id)
|
||||
break
|
||||
@@ -230,7 +234,7 @@ function M.setup(opts)
|
||||
if opts.actions.open_file.window_picker.chars then
|
||||
opts.actions.open_file.window_picker.chars = tostring(opts.actions.open_file.window_picker.chars):upper()
|
||||
end
|
||||
M.window_picker = vim.tbl_extend('force', M.window_picker, opts.actions.open_file.window_picker)
|
||||
M.window_picker = vim.tbl_extend("force", M.window_picker, opts.actions.open_file.window_picker)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -2,7 +2,7 @@ local git = require "nvim-tree.git"
|
||||
local diagnostics = require "nvim-tree.diagnostics"
|
||||
local view = require "nvim-tree.view"
|
||||
local renderer = require "nvim-tree.renderer"
|
||||
local explorer_module = require'nvim-tree.explorer'
|
||||
local explorer_module = require "nvim-tree.explorer"
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
local a = vim.api
|
||||
local luv = vim.loop
|
||||
|
||||
local utils = require'nvim-tree.utils'
|
||||
local events = require'nvim-tree.events'
|
||||
local utils = require "nvim-tree.utils"
|
||||
local events = require "nvim-tree.events"
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -15,13 +15,13 @@ local function close_windows(windows)
|
||||
end
|
||||
|
||||
local function clear_buffer(absolute_path)
|
||||
local bufs = vim.fn.getbufinfo({bufloaded = 1, buflisted = 1})
|
||||
local bufs = vim.fn.getbufinfo { bufloaded = 1, buflisted = 1 }
|
||||
for _, buf in pairs(bufs) do
|
||||
if buf.name == absolute_path then
|
||||
if buf.hidden == 0 and #bufs > 1 then
|
||||
local winnr = a.nvim_get_current_win()
|
||||
a.nvim_set_current_win(buf.windows[1])
|
||||
vim.cmd(':bn')
|
||||
vim.cmd ":bn"
|
||||
a.nvim_set_current_win(winnr)
|
||||
end
|
||||
a.nvim_buf_delete(buf.bufnr, { force = true })
|
||||
@@ -33,21 +33,27 @@ end
|
||||
|
||||
local function remove_dir(cwd)
|
||||
local handle = luv.fs_scandir(cwd)
|
||||
if type(handle) == 'string' then
|
||||
if type(handle) == "string" then
|
||||
return a.nvim_err_writeln(handle)
|
||||
end
|
||||
|
||||
while true do
|
||||
local name, t = luv.fs_scandir_next(handle)
|
||||
if not name then break end
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
|
||||
local new_cwd = utils.path_join({cwd, name})
|
||||
if t == 'directory' then
|
||||
local new_cwd = utils.path_join { cwd, name }
|
||||
if t == "directory" then
|
||||
local success = remove_dir(new_cwd)
|
||||
if not success then return false end
|
||||
if not success then
|
||||
return false
|
||||
end
|
||||
else
|
||||
local success = luv.fs_unlink(new_cwd)
|
||||
if not success then return false end
|
||||
if not success then
|
||||
return false
|
||||
end
|
||||
clear_buffer(new_cwd)
|
||||
end
|
||||
end
|
||||
@@ -55,29 +61,30 @@ local function remove_dir(cwd)
|
||||
return luv.fs_rmdir(cwd)
|
||||
end
|
||||
|
||||
|
||||
function M.fn(node)
|
||||
if node.name == '..' then return end
|
||||
if node.name == ".." then
|
||||
return
|
||||
end
|
||||
|
||||
print("Remove " ..node.name.. " ? y/n")
|
||||
print("Remove " .. node.name .. " ? y/n")
|
||||
local ans = utils.get_user_input_char()
|
||||
utils.clear_prompt()
|
||||
if ans:match('^y') then
|
||||
if ans:match "^y" then
|
||||
if node.nodes ~= nil and not node.link_to then
|
||||
local success = remove_dir(node.absolute_path)
|
||||
if not success then
|
||||
return a.nvim_err_writeln('Could not remove '..node.name)
|
||||
return a.nvim_err_writeln("Could not remove " .. node.name)
|
||||
end
|
||||
events._dispatch_folder_removed(node.absolute_path)
|
||||
else
|
||||
local success = luv.fs_unlink(node.absolute_path)
|
||||
if not success then
|
||||
return a.nvim_err_writeln('Could not remove '..node.name)
|
||||
return a.nvim_err_writeln("Could not remove " .. node.name)
|
||||
end
|
||||
events._dispatch_file_removed(node.absolute_path)
|
||||
clear_buffer(node.absolute_path)
|
||||
end
|
||||
require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,37 +1,39 @@
|
||||
local a = vim.api
|
||||
local uv = vim.loop
|
||||
|
||||
local lib = require'nvim-tree.lib'
|
||||
local utils = require'nvim-tree.utils'
|
||||
local events = require'nvim-tree.events'
|
||||
local lib = require "nvim-tree.lib"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local events = require "nvim-tree.events"
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.fn(with_sub)
|
||||
return function(node)
|
||||
node = lib.get_last_group_node(node)
|
||||
if node.name == '..' then return end
|
||||
if node.name == ".." then
|
||||
return
|
||||
end
|
||||
|
||||
local namelen = node.name:len()
|
||||
local abs_path = with_sub and node.absolute_path:sub(0, namelen * (-1) -1) or node.absolute_path
|
||||
local new_name = vim.fn.input("Rename " ..node.name.. " to ", abs_path)
|
||||
local abs_path = with_sub and node.absolute_path:sub(0, namelen * -1 - 1) or node.absolute_path
|
||||
local new_name = vim.fn.input("Rename " .. node.name .. " to ", abs_path)
|
||||
utils.clear_prompt()
|
||||
if not new_name or #new_name == 0 then
|
||||
return
|
||||
end
|
||||
if utils.file_exists(new_name) then
|
||||
utils.warn("Cannot rename: file already exists")
|
||||
utils.warn "Cannot rename: file already exists"
|
||||
return
|
||||
end
|
||||
|
||||
local success = uv.fs_rename(node.absolute_path, new_name)
|
||||
if not success then
|
||||
return a.nvim_err_writeln('Could not rename '..node.absolute_path..' to '..new_name)
|
||||
return a.nvim_err_writeln("Could not rename " .. node.absolute_path .. " to " .. new_name)
|
||||
end
|
||||
a.nvim_out_write(node.absolute_path..' ➜ '..new_name..'\n')
|
||||
a.nvim_out_write(node.absolute_path .. " ➜ " .. new_name .. "\n")
|
||||
utils.rename_loaded_buffers(node.absolute_path, new_name)
|
||||
events._dispatch_node_renamed(abs_path, new_name)
|
||||
require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local utils = require("nvim-tree.utils")
|
||||
local utils = require "nvim-tree.utils"
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -6,16 +6,16 @@ local M = {}
|
||||
---Safely handles the node representing the current directory
|
||||
---(the topmost node in the nvim-tree window)
|
||||
local function get_node_path(node)
|
||||
if node.name == ".." then
|
||||
return utils.path_remove_trailing(TreeExplorer.cwd)
|
||||
else
|
||||
return node.absolute_path
|
||||
end
|
||||
if node.name == ".." then
|
||||
return utils.path_remove_trailing(TreeExplorer.cwd)
|
||||
else
|
||||
return node.absolute_path
|
||||
end
|
||||
end
|
||||
|
||||
function M.run_file_command(node)
|
||||
local node_path = get_node_path(node)
|
||||
vim.api.nvim_input(": " .. node_path .. "<Home>")
|
||||
local node_path = get_node_path(node)
|
||||
vim.api.nvim_input(": " .. node_path .. "<Home>")
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
local utils = require"nvim-tree.utils"
|
||||
local view = require"nvim-tree.view"
|
||||
local renderer = require"nvim-tree.renderer"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local view = require "nvim-tree.view"
|
||||
local renderer = require "nvim-tree.renderer"
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.fn()
|
||||
if not TreeExplorer then return end
|
||||
if not TreeExplorer then
|
||||
return
|
||||
end
|
||||
|
||||
local input_path = vim.fn.input("Search node: ", "", "file")
|
||||
utils.clear_prompt()
|
||||
|
||||
local absolute_input_path = utils.path_join({
|
||||
local absolute_input_path = utils.path_join {
|
||||
TreeExplorer.cwd,
|
||||
input_path
|
||||
})
|
||||
input_path,
|
||||
}
|
||||
|
||||
local function count_visible_nodes(nodes)
|
||||
local visible_nodes = 0
|
||||
@@ -44,7 +46,7 @@ function M.fn()
|
||||
|
||||
if node.nodes then
|
||||
-- e.g. user searches for "/foo/bar.txt", than directory "/foo/bar" should not match with filename
|
||||
local matches = utils.str_find(absolute_input_path, node.absolute_path .. '/')
|
||||
local matches = utils.str_find(absolute_input_path, node.absolute_path .. "/")
|
||||
|
||||
if matches then
|
||||
found_something = true
|
||||
@@ -75,11 +77,11 @@ function M.fn()
|
||||
end
|
||||
|
||||
if found_something and view.is_visible() then
|
||||
if TreeExplorer.cwd ~= '/' and not view.View.hide_root_folder then
|
||||
if TreeExplorer.cwd ~= "/" and not view.View.hide_root_folder then
|
||||
index = index + 1
|
||||
end
|
||||
|
||||
view.set_cursor({index, 0})
|
||||
view.set_cursor { index, 0 }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,33 +2,34 @@ local uv = vim.loop
|
||||
|
||||
local M = {
|
||||
config = {
|
||||
is_windows = vim.fn.has('win32') == 1 or vim.fn.has('win32unix') == 1,
|
||||
is_macos = vim.fn.has('mac') == 1 or vim.fn.has('macunix') == 1,
|
||||
is_unix = vim.fn.has('unix') == 1,
|
||||
}
|
||||
is_windows = vim.fn.has "win32" == 1 or vim.fn.has "win32unix" == 1,
|
||||
is_macos = vim.fn.has "mac" == 1 or vim.fn.has "macunix" == 1,
|
||||
is_unix = vim.fn.has "unix" == 1,
|
||||
},
|
||||
}
|
||||
|
||||
function M.fn(node)
|
||||
if not M.config.system_open.cmd then
|
||||
require'nvim-tree.utils'.warn("Cannot open file with system application. Unrecognized platform.")
|
||||
require("nvim-tree.utils").warn "Cannot open file with system application. Unrecognized platform."
|
||||
return
|
||||
end
|
||||
|
||||
local process = {
|
||||
cmd = M.config.system_open.cmd,
|
||||
args = M.config.system_open.args,
|
||||
errors = '\n',
|
||||
stderr = uv.new_pipe(false)
|
||||
errors = "\n",
|
||||
stderr = uv.new_pipe(false),
|
||||
}
|
||||
table.insert(process.args, node.link_to or node.absolute_path)
|
||||
process.handle, process.pid = uv.spawn(process.cmd,
|
||||
process.handle, process.pid = uv.spawn(
|
||||
process.cmd,
|
||||
{ args = process.args, stdio = { nil, nil, process.stderr }, detached = true },
|
||||
function(code)
|
||||
process.stderr:read_stop()
|
||||
process.stderr:close()
|
||||
process.handle:close()
|
||||
if code ~= 0 then
|
||||
process.errors = process.errors .. string.format('NvimTree system_open: return code %d.', code)
|
||||
process.errors = process.errors .. string.format("NvimTree system_open: return code %d.", code)
|
||||
error(process.errors)
|
||||
end
|
||||
end
|
||||
@@ -38,14 +39,15 @@ function M.fn(node)
|
||||
error("\n" .. process.pid .. "\nNvimTree system_open: failed to spawn process using '" .. process.cmd .. "'.")
|
||||
return
|
||||
end
|
||||
uv.read_start(process.stderr,
|
||||
function(err, data)
|
||||
if err then return end
|
||||
if data then process.errors = process.errors .. data end
|
||||
uv.read_start(process.stderr, function(err, data)
|
||||
if err then
|
||||
return
|
||||
end
|
||||
)
|
||||
if data then
|
||||
process.errors = process.errors .. data
|
||||
end
|
||||
end)
|
||||
uv.unref(process.handle)
|
||||
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
@@ -55,12 +57,12 @@ function M.setup(opts)
|
||||
if M.config.is_windows then
|
||||
M.config.system_open = {
|
||||
cmd = "cmd",
|
||||
args = {'/c', 'start', '""'}
|
||||
args = { "/c", "start", '""' },
|
||||
}
|
||||
elseif M.config.is_macos then
|
||||
M.config.system_open.cmd = 'open'
|
||||
M.config.system_open.cmd = "open"
|
||||
elseif M.config.is_unix then
|
||||
M.config.system_open.cmd = 'xdg-open'
|
||||
M.config.system_open.cmd = "xdg-open"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local view = require"nvim-tree.view"
|
||||
local filters = require"nvim-tree.explorer.filters"
|
||||
local renderer = require"nvim-tree.renderer"
|
||||
local reloaders = require"nvim-tree.actions.reloaders"
|
||||
local view = require "nvim-tree.view"
|
||||
local filters = require "nvim-tree.explorer.filters"
|
||||
local renderer = require "nvim-tree.renderer"
|
||||
local reloaders = require "nvim-tree.actions.reloaders"
|
||||
|
||||
local M = {}
|
||||
|
||||
|
||||
@@ -2,23 +2,23 @@ local a = vim.api
|
||||
|
||||
local M = {
|
||||
config = {
|
||||
is_windows = vim.fn.has('win32') == 1 or vim.fn.has('win32unix') == 1,
|
||||
is_macos = vim.fn.has('mac') == 1 or vim.fn.has('macunix') == 1,
|
||||
is_unix = vim.fn.has('unix') == 1,
|
||||
}
|
||||
is_windows = vim.fn.has "win32" == 1 or vim.fn.has "win32unix" == 1,
|
||||
is_macos = vim.fn.has "mac" == 1 or vim.fn.has "macunix" == 1,
|
||||
is_unix = vim.fn.has "unix" == 1,
|
||||
},
|
||||
}
|
||||
|
||||
local utils = require'nvim-tree.utils'
|
||||
local events = require'nvim-tree.events'
|
||||
local utils = require "nvim-tree.utils"
|
||||
local events = require "nvim-tree.events"
|
||||
|
||||
local function clear_buffer(absolute_path)
|
||||
local bufs = vim.fn.getbufinfo({bufloaded = 1, buflisted = 1})
|
||||
local bufs = vim.fn.getbufinfo { bufloaded = 1, buflisted = 1 }
|
||||
for _, buf in pairs(bufs) do
|
||||
if buf.name == absolute_path then
|
||||
if buf.hidden == 0 and #bufs > 1 then
|
||||
local winnr = a.nvim_get_current_win()
|
||||
a.nvim_set_current_win(buf.windows[1])
|
||||
vim.cmd(':bn')
|
||||
vim.cmd ":bn"
|
||||
a.nvim_set_current_win(winnr)
|
||||
end
|
||||
vim.api.nvim_buf_delete(buf.bufnr, {})
|
||||
@@ -28,20 +28,26 @@ local function clear_buffer(absolute_path)
|
||||
end
|
||||
|
||||
function M.fn(node)
|
||||
if node.name == '..' then return end
|
||||
if node.name == ".." then
|
||||
return
|
||||
end
|
||||
|
||||
-- configs
|
||||
if M.config.is_unix then
|
||||
if M.config.trash.cmd == nil then M.config.trash.cmd = 'trash' end
|
||||
if M.config.trash.require_confirm == nil then M.config.trash.require_confirm = true end
|
||||
if M.config.trash.cmd == nil then
|
||||
M.config.trash.cmd = "trash"
|
||||
end
|
||||
if M.config.trash.require_confirm == nil then
|
||||
M.config.trash.require_confirm = true
|
||||
end
|
||||
else
|
||||
utils.warn('Trash is currently a UNIX only feature!')
|
||||
utils.warn "Trash is currently a UNIX only feature!"
|
||||
return
|
||||
end
|
||||
|
||||
-- trashes a path (file or folder)
|
||||
local function trash_path(on_exit)
|
||||
vim.fn.jobstart(M.config.trash.cmd.." "..node.absolute_path, {
|
||||
vim.fn.jobstart(M.config.trash.cmd .. " " .. node.absolute_path, {
|
||||
detach = true,
|
||||
on_exit = on_exit,
|
||||
})
|
||||
@@ -52,9 +58,11 @@ function M.fn(node)
|
||||
-- confirmation prompt
|
||||
if M.config.trash.require_confirm then
|
||||
is_confirmed = false
|
||||
print("Trash " ..node.name.. " ? y/n")
|
||||
print("Trash " .. node.name .. " ? y/n")
|
||||
local ans = utils.get_user_input_char()
|
||||
if ans:match('^y') then is_confirmed = true end
|
||||
if ans:match "^y" then
|
||||
is_confirmed = true
|
||||
end
|
||||
utils.clear_prompt()
|
||||
end
|
||||
|
||||
@@ -63,16 +71,15 @@ function M.fn(node)
|
||||
if node.nodes ~= nil and not node.link_to then
|
||||
trash_path(function()
|
||||
events._dispatch_folder_removed(node.absolute_path)
|
||||
require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
end)
|
||||
else
|
||||
trash_path(function()
|
||||
events._dispatch_file_removed(node.absolute_path)
|
||||
clear_buffer(node.absolute_path)
|
||||
require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
end)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user