key bind for list of delete marks (#27)

* key bind for list of delete marks

https://github.com/zenyd/mpv-scripts/issues/14

* make show list a toggle so we don't spam the terminal

* put showListTimer:resume() in condition

* undelete all and globalize timer

if timer is local showList() can't reference it

* add new keybinds

* add space to help wrapping

* better matching
This commit is contained in:
bitingsock 2021-03-07 03:31:37 -08:00 committed by GitHub
parent 019fb5346c
commit efa300fb6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -65,3 +65,5 @@ First invoke the script using `alt + u`, input a movie name, or use the one prov
As the name suggests this is a small script for deleting files played through mpv. You can mark a file to be deleted and can unmark it if desired. Once quitting mpv, the script starts the deletion process. This is platform-agnostic so should work everywhere.
`ctrl + DEL`: mark/unmark file to be deleted
`alt + DEL`: show the list of files marked for deletion
`ctrl + shift + DEL`: clear the list of marks

View File

@ -36,5 +36,37 @@ function delete()
end
end
function showList()
local delString = "Delete Marks:\n"
for _,v in pairs(del_list) do
local dFile = v:gsub("/","\\")
delString = delString..dFile:match("\\*([^\\]*)$").."; "
end
if delString:find(";") then
mp.osd_message(delString)
return delString
elseif showListTimer then
showListTimer:kill()
end
end
showListTimer = mp.add_periodic_timer(1,showList)
showListTimer:kill()
function list_marks()
if showListTimer:is_enabled() then
showListTimer:kill()
mp.osd_message("",0)
else
local delString = showList()
if delString and delString:find(";") then
showListTimer:resume()
print(delString)
else
showListTimer:kill()
end
end
end
mp.add_key_binding("ctrl+DEL", "delete_file", mark_delete)
mp.add_key_binding("alt+DEL", "list_marks", list_marks)
mp.add_key_binding("ctrl+shift+DEL", "clear_list", function() mp.osd_message("Undelete all"); del_list = {}; end)
mp.register_event("shutdown", delete)