Skip to content

Commit 7a3c6d1

Browse files
committed
remove some builtins
1 parent 8cc7507 commit 7a3c6d1

6 files changed

Lines changed: 393 additions & 262 deletions

File tree

doc/neo-tree.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -987,9 +987,14 @@ this is bound to `T`.
987987

988988
The default commands that neo-tree tries to use, in order, are:
989989

990-
MacOS: `trash`, or `osascript` commands.
991-
992-
Linux: `gio trash`, `trash`, and `kioclient/kioclient5`.
990+
MacOS:
991+
- `trash`,
992+
- `osascript` commands.
993+
994+
Linux:
995+
- `trash-put/restore` from https://github.com/andreafrancia/trash-cli
996+
- `gio trash`
997+
- `kioclient/kioclient5`.
993998

994999
Windows: `trash`, or `PowerShell` commands.
9951000

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

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local uv = vim.uv or vim.loop
88
local scan = require("plenary.scandir")
99
local utils = require("neo-tree.utils")
1010
local inputs = require("neo-tree.ui.inputs")
11-
local trash = require("neo-tree.sources.filesystem.lib.trash")
11+
local trash = require("neo-tree.trash.init")
1212
local events = require("neo-tree.events")
1313
local log = require("neo-tree.log")
1414
local Path = require("plenary.path")
@@ -82,6 +82,16 @@ local setup_file_completion = function(root, filter)
8282
return "customlist,v:lua.require'neo-tree.sources.filesystem.lib.fs_actions'._file_completion"
8383
end
8484

85+
---@param path string
86+
local count_children = function(path)
87+
return #scan.scan_dir(path, {
88+
hidden = true,
89+
respect_gitignore = false,
90+
add_dirs = true,
91+
depth = 1,
92+
})
93+
end
94+
8595
---@param a uv.fs_stat.result?
8696
---@param b uv.fs_stat.result?
8797
---@return boolean equal Whether a and b are stats of the same file
@@ -634,12 +644,7 @@ M.delete_node = function(path, callback, noconfirm)
634644
_type = uv.fs_stat(link_to).type
635645
end
636646
if _type == "directory" then
637-
children_count = #scan.scan_dir(path, {
638-
hidden = true,
639-
respect_gitignore = false,
640-
add_dirs = true,
641-
depth = 1,
642-
})
647+
children_count = count_children(path)
643648
end
644649
end
645650

@@ -740,40 +745,7 @@ M.trash_node = function(path, callback)
740745
local _, name = utils.split_path(path)
741746

742747
log.trace("Deleting node:", path)
743-
local _type = "unknown"
744-
local stat = uv.fs_lstat(path)
745-
local children_count = 0
746-
if not stat then
747-
log.warn("Could not read file/dir:", path, stat, ", attempting to trash anyway...")
748-
-- Guess the type by whether it appears to have an extension
749-
if path:match("%.(.+)$") then
750-
_type = "file"
751-
else
752-
_type = "directory"
753-
end
754-
else
755-
_type = stat.type
756-
if _type == "link" then
757-
local link_to = uv.fs_realpath(path)
758-
if not link_to then
759-
log.error("Could not read link")
760-
return
761-
end
762-
local target_file = uv.fs_stat(link_to)
763-
if target_file then
764-
_type = target_file.type
765-
end
766-
_type = uv.fs_stat(link_to).type
767-
end
768-
if _type == "directory" then
769-
children_count = #scan.scan_dir(path, {
770-
hidden = true,
771-
respect_gitignore = false,
772-
add_dirs = true,
773-
depth = 1,
774-
})
775-
end
776-
end
748+
local stat = uv.fs_stat(path)
777749

778750
local do_trash = function()
779751
local complete = vim.schedule_wrap(function()
@@ -798,14 +770,11 @@ M.trash_node = function(path, callback)
798770
complete()
799771
end
800772

801-
local msg = string.format("Are you sure you want to trash '%s'?", name)
802-
if children_count > 0 then
803-
msg = ("WARNING: Dir has %s %s! %s"):format(
804-
children_count,
805-
children_count == 1 and "child" or "children",
806-
msg
807-
)
773+
local displayed_name = name
774+
if stat and stat.type == "directory" then
775+
displayed_name = name .. utils.path_separator
808776
end
777+
local msg = string.format("Are you sure you want to trash '%s'?", displayed_name)
809778
inputs.confirm(msg, function(confirmed)
810779
if confirmed then
811780
do_trash()
@@ -814,7 +783,7 @@ M.trash_node = function(path, callback)
814783
end
815784

816785
---@param paths_to_trash string[]
817-
---@param callback fun(path)?
786+
---@param callback fun(path: string)?
818787
M.trash_nodes = function(paths_to_trash, callback)
819788
local msg = "Are you sure you want to delete " .. #paths_to_trash .. " items?"
820789
inputs.confirm(msg, function(confirmed)

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

Lines changed: 0 additions & 194 deletions
This file was deleted.

0 commit comments

Comments
 (0)