Repository navigation
Lua script that navigates to Trash folder and activates trashwdx columns #91
Closed
advice2020
started this conversation in
Ideas
Replies: 3 comments
|
@j2969719 |
0 replies
|
Old script: -- ListOfTrashFolders.lua (Linux only)
-- 2020.03.31
--[[
Find all available trash folders:
~/.local/share/Trash/files
<mount point>/.Trash/<UID>/files
<mount point>/.Trash-<UID>/files
where <UID> is user ID. Will be checked devices
/dev/fd
/dev/hd
/dev/sd
/dev/nvme
Command:
cm_ExecuteScript
Parameters:
/path/to/script/ListOfTrashFolders.lua
Optional parameters:
--new-tab
open directory in new tab;
columnset
switch to columns view (cm_ColumnsView) with user defined column set "columnset" ***
(without quotes).
NOTE: If both parameters then "--new-tab" must be first!
*** For example, with trashwdx.lua (https://github.com/j2969719/doublecmd-plugins/blob/master/plugins/wdx/scripts/trashwdx.lua)
]]
local function GetUser()
local h = io.popen('id')
if not h then return nil end
local o = h:read("*a")
h:close()
local i, s = string.match(o, 'uid=([^(]+)%(([^)]+)%)')
if i == nil then
return nil
else
return i, s
end
end
local params = {...}
if #params > 2 then
Dialogs.MessageBox('Check parameters!', 'ListOfTrashFolders', 0x0010)
return
end
local list = {}
local uid, user = GetUser()
if uid == nil then
Dialogs.MessageBox('Unknown error 1.', 'ListOfTrashFolders', 0x0010)
return
end
if SysUtils.DirectoryExists('/home/' .. user .. '/.local/share/Trash/files') == true then
table.insert(list, '/home/' .. user .. '/.local/share/Trash/files')
end
local td, tp
local mp = {}
local dev = {}
local h = io.open('/etc/mtab', 'r')
if not h then
Dialogs.MessageBox('/etc/mtab: cannot be read.', 'ListOfTrashFolders', 0x0010)
return
end
for l in h:lines() do
t = string.sub(l, 1, 7)
if (t == '/dev/fd') or (t == '/dev/hd') or (t == '/dev/sd') or (string.sub(l, 1, 9) == '/dev/nvme') then
td, tp = string.match(l, '^([^ ]+) ([^ ]+) ')
if td ~= nil then
table.insert(dev, td)
table.insert(mp, tp)
end
end
end
h:close()
if #mp > 0 then
for i = 1, #mp do
if SysUtils.DirectoryExists(mp[i] .. '/.Trash/' .. uid .. '/files') == true then
table.insert(list, dev[i] .. ' (' .. mp[i] .. '/.Trash/' .. uid .. '/files)')
end
if SysUtils.DirectoryExists(mp[i] .. '/.Trash-' .. uid .. '/files') == true then
table.insert(list, dev[i] .. ' (' .. mp[i] .. '/.Trash-' .. uid .. '/files)')
end
end
end
if #list == 0 then
Dialogs.MessageBox('Not found.', 'ListOfTrashFolders', 0x0040)
return
end
local r = Dialogs.InputListBox('All trash folders', #list .. ' folder(s) found:', list, 1)
if r == nil then return end
local n = string.find(r, ' (', 1, true)
if n ~= nil then r = string.sub(r, n + 2, -2) end
local nt, cs
if #params == 1 then
if params[1] == '--new-tab' then
nt = true
else
cs = params[1]
end
elseif #params == 2 then
nt = true
cs = params[2]
end
if nt == true then DC.ExecuteCommand("cm_NewTab") end
DC.ExecuteCommand("cm_ChangeDir", r)
if cs ~= nil then
DC.ExecuteCommand("cm_ColumnsView", "columnset=" .. cs)
end(But I think it's better to check that the "files" subfolder is not empty.) |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I just made the following post #90 about an issue I am experiencing with the WDX
trashwdx.luascript.Because DC resorts back to its default Trash column set any time that folder is accessed,
I was wondering if anyone ever created/uses a simple script that would....
-navigates to
trash://folder-then auto-loads custom column set generated using this
trashwdx.luascriptto override the DC default Trash column set from appearing
If not, then would anyone be willing to create a Lua script to achieve this?
This way at least the Trash folder would be able to be opened with a hotkey and with users choice of columns to be viewed.
Thank you to anyone who reads this and for any help provided.
All reactions