yazi: quick-folder plugin
This commit is contained in:
parent
6ba3ec800f
commit
8d24bc9d9d
4 changed files with 87 additions and 0 deletions
20
home.nix
20
home.nix
|
|
@ -336,6 +336,7 @@ in {
|
||||||
rev = "2e8079e4a7f6315de99a5b968ed5fda479f1f39c";
|
rev = "2e8079e4a7f6315de99a5b968ed5fda479f1f39c";
|
||||||
hash = "sha256-wHTR8frrFL3cUD8fvSTO+m/77wQ7auVjTZ1uCTB/UzU=";
|
hash = "sha256-wHTR8frrFL3cUD8fvSTO+m/77wQ7auVjTZ1uCTB/UzU=";
|
||||||
};
|
};
|
||||||
|
quick-folder = ./quick-folder.yazi;
|
||||||
};
|
};
|
||||||
settings = {
|
settings = {
|
||||||
plugin.prepend_previewers = [
|
plugin.prepend_previewers = [
|
||||||
|
|
@ -347,6 +348,25 @@ in {
|
||||||
# larger rename box
|
# larger rename box
|
||||||
input.rename_offset = [0 1 200 3];
|
input.rename_offset = [0 1 200 3];
|
||||||
};
|
};
|
||||||
|
keymap = {
|
||||||
|
mgr.prepend_keymap = [
|
||||||
|
{
|
||||||
|
on = ["g" "j"];
|
||||||
|
run = "cd ~/Johnny.Decimal";
|
||||||
|
desc = "Go to Johnny Decimal";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
on = "A";
|
||||||
|
run = "create --dir";
|
||||||
|
desc = "Create directory";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
on = "b";
|
||||||
|
run = ["plugin quick-folder"];
|
||||||
|
desc = "Create directory with name of hovered file and move selected files into it";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
xsession.windowManager.xmonad = {
|
xsession.windowManager.xmonad = {
|
||||||
|
|
|
||||||
2
quick-folder.yazi/LICENSE
Normal file
2
quick-folder.yazi/LICENSE
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
Copyright 2025 Khaïs COLIN
|
||||||
|
All rights reserved
|
||||||
5
quick-folder.yazi/README.md
Normal file
5
quick-folder.yazi/README.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
Create a new folder and quickly move files into it
|
||||||
|
|
||||||
|
The name of the new folder is the first selected file, or the hovered file if no files are selected, and can be edited before creation
|
||||||
|
|
||||||
|
The files moved into the new folder are all selected files, or the hovered file if no files are selected
|
||||||
60
quick-folder.yazi/main.lua
Normal file
60
quick-folder.yazi/main.lua
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
local get_hovered_url = ya.sync(function(state)
|
||||||
|
if not state.hovered_url then
|
||||||
|
state.hovered_url = cx.active.current.hovered.url
|
||||||
|
end
|
||||||
|
return Url(state.hovered_url)
|
||||||
|
end)
|
||||||
|
|
||||||
|
local get_selected_files = ya.sync(function(state)
|
||||||
|
local selected = {}
|
||||||
|
for _, url in pairs(cx.active.selected) do
|
||||||
|
selected[#selected + 1] = url
|
||||||
|
end
|
||||||
|
return selected
|
||||||
|
end)
|
||||||
|
|
||||||
|
local get_wanted_dir_name = function()
|
||||||
|
local url = get_selected_files()[0] or get_hovered_url()
|
||||||
|
local name = url.stem
|
||||||
|
local edited, event = ya.input {
|
||||||
|
title = "Dir name:",
|
||||||
|
value = name,
|
||||||
|
position = {"hovered", x = 0, y = 0, w = 200, h = 3}
|
||||||
|
}
|
||||||
|
ya.dbg("got dir name from user", edited, "with confirm", event)
|
||||||
|
if event == 1 then -- did user confirm?
|
||||||
|
return Url(edited)
|
||||||
|
else
|
||||||
|
return undefined
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local get_files_to_move = function()
|
||||||
|
local files_to_move = get_selected_files()
|
||||||
|
if #files_to_move == 0 then
|
||||||
|
files_to_move[1] = get_hovered_url()
|
||||||
|
end
|
||||||
|
return files_to_move
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
entry = function(state, job)
|
||||||
|
state.hovered_url = undefined
|
||||||
|
local wanted_dir_name = get_wanted_dir_name()
|
||||||
|
if not wanted_dir_name then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local ok, err = fs.create("dir", wanted_dir_name)
|
||||||
|
if not ok then
|
||||||
|
ya.notify { title = "Failed to create directory", content = err }
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local files_to_move = get_files_to_move()
|
||||||
|
ya.dbg("files to move", files_to_move)
|
||||||
|
for i, file in pairs(files_to_move) do
|
||||||
|
local dest = wanted_dir_name:join(file.name)
|
||||||
|
ya.dbg("moving file", i, "of", #files_to_move, file, "to", dest)
|
||||||
|
os.rename(tostring(file), tostring(dest))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue