From efa300fb6b666530fc6b3ae0d748266f27d150e1 Mon Sep 17 00:00:00 2001 From: bitingsock Date: Sun, 7 Mar 2021 03:31:37 -0800 Subject: [PATCH] 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 --- README.md | 2 ++ delete_file.lua | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/README.md b/README.md index 2574ff9..537535a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/delete_file.lua b/delete_file.lua index ca78398..635b1dc 100644 --- a/delete_file.lua +++ b/delete_file.lua @@ -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)