delete-file: option to move instead of delete
This commit is contained in:
parent
d5ea82a604
commit
885b9bd056
|
@ -70,6 +70,10 @@ Key Bind|Effect
|
||||||
`alt + DEL`|show the list of files marked for deletion
|
`alt + DEL`|show the list of files marked for deletion
|
||||||
`ctrl + shift + DEL`|clear the list of marked files
|
`ctrl + shift + DEL`|clear the list of marked files
|
||||||
|
|
||||||
|
The script can be configured to move files instead of deleting them. The default folder for the moved files is `C:\Users\<me>\delete_file`. To change the defaults create a `delete_file.conf` inside of the `script-opts` folder with contents:
|
||||||
|
```
|
||||||
|
MoveToFolder=yes
|
||||||
|
```
|
||||||
|
|
||||||
## copy-paste-URL
|
## copy-paste-URL
|
||||||
Like its name suggests - copy and paste links into mpv with `ctrl + v` to start playback of a video. This needs an open mpv window like `mpv --idle --force-window` or a window already playing a video. Also the script utilizes powershell, so that needs to be installed as well.
|
Like its name suggests - copy and paste links into mpv with `ctrl + v` to start playback of a video. This needs an open mpv window like `mpv --idle --force-window` or a window already playing a video. Also the script utilizes powershell, so that needs to be installed as well.
|
||||||
|
|
|
@ -1,7 +1,31 @@
|
||||||
local utils = require "mp.utils"
|
local utils = require "mp.utils"
|
||||||
|
|
||||||
|
require 'mp.options'
|
||||||
|
|
||||||
|
options = {}
|
||||||
|
options.MoveToFolder = false
|
||||||
|
|
||||||
|
if package.config:sub(1,1) == "/" then
|
||||||
|
options.DeletedFilesPath = utils.join_path(os.getenv("HOME"), "delete_file")
|
||||||
|
ops = "unix"
|
||||||
|
else
|
||||||
|
options.DeletedFilesPath = utils.join_path(os.getenv("USERPROFILE"), "delete_file")
|
||||||
|
ops = "win"
|
||||||
|
end
|
||||||
|
|
||||||
|
read_options(options)
|
||||||
|
|
||||||
|
|
||||||
del_list = {}
|
del_list = {}
|
||||||
|
|
||||||
|
function createDirectory()
|
||||||
|
if not utils.file_info(options.DeletedFilesPath) then
|
||||||
|
if not os.execute(string.format('mkdir "%s"', options.DeletedFilesPath)) then
|
||||||
|
print("failed to create folder")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function contains_item(l, i)
|
function contains_item(l, i)
|
||||||
for k, v in pairs(l) do
|
for k, v in pairs(l) do
|
||||||
if v == i then
|
if v == i then
|
||||||
|
@ -30,9 +54,37 @@ function mark_delete()
|
||||||
end
|
end
|
||||||
|
|
||||||
function delete()
|
function delete()
|
||||||
|
if options.MoveToFolder then
|
||||||
|
--create folder if not exists
|
||||||
|
createDirectory()
|
||||||
|
end
|
||||||
|
|
||||||
for i, v in pairs(del_list) do
|
for i, v in pairs(del_list) do
|
||||||
print("deleting: "..v)
|
if options.MoveToFolder then
|
||||||
os.remove(v)
|
print("moving: "..v)
|
||||||
|
local _, file_name = utils.split_path(v)
|
||||||
|
--this loop will add a number to the file name if it already exists in the directory
|
||||||
|
--But limit the number of iterations
|
||||||
|
for i = 1,100 do
|
||||||
|
if i > 1 then
|
||||||
|
if file_name:find("[.].+$") then
|
||||||
|
file_name = file_name:gsub("([.].+)$", string.format("_%d%%1", i))
|
||||||
|
else
|
||||||
|
file_name = string.format("%s_%d", file_name, i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local movedPath = utils.join_path(options.DeletedFilesPath, file_name)
|
||||||
|
local fileInfo = utils.file_info(movedPath)
|
||||||
|
if not fileInfo then
|
||||||
|
os.rename(v, movedPath)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
print("deleting: "..v)
|
||||||
|
os.remove(v)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue