feat: trash support for linux and mac (#165)
* wip: skeleton code for trash adapter * refactor: split trash implementation for mac and linux * fix: ensure we create the .Trash/$uid dir * feat: code complete linux trash implementation * doc: write up trash features * feat: code complete mac trash implementation * cleanup: remove previous, terrible, undocumented trash feature * fix: always disabled trash * feat: show original path of trashed files * doc: add a note about calling actions directly * fix: bugs in trash implementation * fix: schedule_wrap in mac trash * doc: fix typo and line wrapping * fix: parsing of arguments to :Oil command * doc: small documentation tweaks * doc: fix awkward wording in the toggle_trash action * fix: warning on Windows when delete_to_trash = true * feat: :Oil --trash can open specific trash directories * fix: show all trash files in device root * fix: trash mtime should be sortable * fix: shorten_path handles optional trailing slash * refactor: overhaul the UI * fix: keep trash original path vtext from stacking * refactor: replace disable_changes with an error filter * fix: shorten path names in home directory relative to root * doc: small README format changes * cleanup: remove unnecessary preserve_undo logic * test: add a functional test for the freedesktop trash adapter * test: more functional tests for trash * fix: schedule a callback to avoid main loop error * refactor: clean up mutator logic * doc: some comments and type annotations
This commit is contained in:
parent
d8f0d91b10
commit
6175bd6462
27 changed files with 1580 additions and 229 deletions
|
|
@ -7,6 +7,8 @@ M.is_windows = uv.os_uname().version:match("Windows")
|
|||
|
||||
M.is_mac = uv.os_uname().sysname == "Darwin"
|
||||
|
||||
M.is_linux = not M.is_windows and not M.is_mac
|
||||
|
||||
---@type string
|
||||
M.sep = M.is_windows and "\\" or "/"
|
||||
|
||||
|
|
@ -114,20 +116,31 @@ end
|
|||
local home_dir = assert(uv.os_homedir())
|
||||
|
||||
---@param path string
|
||||
---@param relative_to? string Shorten relative to this path (default cwd)
|
||||
---@return string
|
||||
M.shorten_path = function(path)
|
||||
local cwd = vim.fn.getcwd()
|
||||
if M.is_subpath(cwd, path) then
|
||||
local relative = path:sub(cwd:len() + 2)
|
||||
if relative == "" then
|
||||
relative = "."
|
||||
M.shorten_path = function(path, relative_to)
|
||||
if not relative_to then
|
||||
relative_to = vim.fn.getcwd()
|
||||
end
|
||||
local relpath
|
||||
if M.is_subpath(relative_to, path) then
|
||||
local idx = relative_to:len() + 1
|
||||
-- Trim the dividing slash if it's not included in relative_to
|
||||
if not vim.endswith(relative_to, "/") and not vim.endswith(relative_to, "\\") then
|
||||
idx = idx + 1
|
||||
end
|
||||
relpath = path:sub(idx)
|
||||
if relpath == "" then
|
||||
relpath = "."
|
||||
end
|
||||
return relative
|
||||
end
|
||||
if M.is_subpath(home_dir, path) then
|
||||
return "~" .. path:sub(home_dir:len() + 1)
|
||||
local homepath = "~" .. path:sub(home_dir:len() + 1)
|
||||
if not relpath or homepath:len() < relpath:len() then
|
||||
return homepath
|
||||
end
|
||||
end
|
||||
return path
|
||||
return relpath or path
|
||||
end
|
||||
|
||||
M.mkdirp = function(dir)
|
||||
|
|
@ -177,7 +190,7 @@ M.listdir = function(dir, cb)
|
|||
end
|
||||
read_next()
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
end, 100) -- TODO do some testing for this
|
||||
end, 10000)
|
||||
end
|
||||
|
||||
---@param entry_type oil.EntryType
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue