From 6ef00fe663fe193bca32e30e64578bec07de5856 Mon Sep 17 00:00:00 2001 From: Crony Akatsuki Date: Wed, 5 Nov 2025 19:28:54 +0100 Subject: [PATCH] feat(yazi): add some more plugins to yazi. --- modules/cross-platform/home-manager/shell.nix | 125 ++++++++++++++++-- .../cross-platform/home-manager/yazi/init.lua | 43 ++++++ .../home-manager/yazi/parent-arrow/main.lua | 20 +++ 3 files changed, 177 insertions(+), 11 deletions(-) create mode 100644 modules/cross-platform/home-manager/yazi/init.lua create mode 100644 modules/cross-platform/home-manager/yazi/parent-arrow/main.lua diff --git a/modules/cross-platform/home-manager/shell.nix b/modules/cross-platform/home-manager/shell.nix index 8d2649c..73b2689 100644 --- a/modules/cross-platform/home-manager/shell.nix +++ b/modules/cross-platform/home-manager/shell.nix @@ -154,24 +154,89 @@ show_hidden = true; show_symlink = false; }; + plugin = { + prepend_fetchers = [ + { + id = "git"; + name = "*"; + run = "git"; + } + { + id = "git"; + name = "*/"; + run = "git"; + } + ]; + prepend_previewers = [ + # Archive previewer + { + mime = "application/*zip"; + run = "ouch"; + } + { + mime = "application/x-tar"; + run = "ouch"; + } + { + mime = "application/x-bzip2"; + run = "ouch"; + } + { + mime = "application/x-7z-compressed"; + run = "ouch"; + } + { + mime = "application/x-rar"; + run = "ouch"; + } + { + mime = "application/vnd.rar"; + run = "ouch"; + } + { + mime = "application/x-xz"; + run = "ouch"; + } + { + mime = "application/xz"; + run = "ouch"; + } + { + mime = "application/x-zstd"; + run = "ouch"; + } + { + mime = "application/zstd"; + run = "ouch"; + } + { + mime = "application/java-archive"; + run = "ouch"; + } + ]; + opener = { + extract = [ + { + run = "ouch -d -y \"$@\""; + desc = "Extract here with ouch"; + } + ]; + }; + }; }; plugins = { full-border = pkgs.yaziPlugins.full-border; smart-enter = pkgs.yaziPlugins.smart-enter; smart-tab = ./yazi/smart-tab; folder-rules = ./yazi/folder-rules; + toggle-pane = pkgs.yaziPlugins.toggle-pane; + parent-arrow = ./yazi/parent-arrow; + chmod = pkgs.yaziPlugins.chmod; + ouch = pkgs.yaziPlugins.ouch; + git = pkgs.yaziPlugins.git; + mount = pkgs.yaziPlugins.mount; }; - initLua = '' - require("full-border"):setup({ - type = ui.Border.ROUNDED, - }) - - require("smart-enter"):setup({ - open_multi = true, - }) - - require("folder-rules"):setup() - ''; + initLua = ./yazi/init.lua; keymap = { mgr.prepend_keymap = [ { @@ -184,6 +249,44 @@ run = "plugin smart-tab"; desc = "Create a tab and enter the howered directory"; } + { + on = ""; + for = "linux"; + run = "shell -- hyprctl hyprpaper reload , \"$0\""; + desc = "Set howered file as wallpaper"; + } + { + on = [" " "p"]; + run = "plugin toggle-pane min-preview"; + desc = "Show or hide the preview pane"; + } + { + on = "K"; + run = "plugin parent-arrow -1"; + } + { + on = "J"; + run = "plugin parent-arrow 1"; + } + { + on = ["g" "r"]; + run = "shell -- ya emit cd \"$(git rev-parse --show-toplevel)\""; + } + { + on = ["c" "m"]; + run = "plugin chmod"; + desc = "Chmod on selected files"; + } + { + on = "C"; + run = "plugin ouch tar.gz"; + desc = "Compress with ouch"; + } + { + on = "M"; + run = "plugin mount"; + desc = "Manage mounting disks"; + } ]; }; }; diff --git a/modules/cross-platform/home-manager/yazi/init.lua b/modules/cross-platform/home-manager/yazi/init.lua new file mode 100644 index 0000000..14cb10f --- /dev/null +++ b/modules/cross-platform/home-manager/yazi/init.lua @@ -0,0 +1,43 @@ +-- Hide preview pane by default +require("toggle-pane"):entry("min-preview") + +-- Have nice rounded border +require("full-border"):setup({ + type = ui.Border.ROUNDED, +}) + +-- Smartly enter directory or open file +require("smart-enter"):setup({ + open_multi = true, +}) + +-- Setup some folder rules +require("folder-rules"):setup() + +-- Show git status of files +require("git"):setup() + +-- Show symlink in status bar +Status:children_add(function(self) + local h = self._current.hovered + if h and h.link_to then + return " -> " .. tostring(h.link_to) + else + return "" + end +end, 3300, Status.LEFT) + +-- Show user/group of file in status bar +Status:children_add(function() + local h = cx.active.current.hovered + if not h or ya.target_family() ~= "unix" then + return "" + end + + return ui.Line { + ui.Span(ya.user_name(h.cha.uid) or tostring(h.cha.uid)):fg("magenta"), + ":", + ui.Span(ya.group_name(h.cha.gid) or tostring(h.cha.gid)):fg("magenta"), + " ", + } +end, 500, Status.RIGHT) diff --git a/modules/cross-platform/home-manager/yazi/parent-arrow/main.lua b/modules/cross-platform/home-manager/yazi/parent-arrow/main.lua new file mode 100644 index 0000000..723bce6 --- /dev/null +++ b/modules/cross-platform/home-manager/yazi/parent-arrow/main.lua @@ -0,0 +1,20 @@ +--- @sync entry +local function entry(_, job) + local parent = cx.active.parent + if not parent then return end + + local offset = tonumber(job.args[1]) + if not offset then return ya.err(job.args[1], 'is not a number') end + + local start = parent.cursor + 1 + offset + local end_ = offset < 0 and 1 or #parent.files + local step = offset < 0 and -1 or 1 + for i = start, end_, step do + local target = parent.files[i] + if target and target.cha.is_dir then + return ya.emit("cd", { target.url }) + end + end +end + +return { entry = entry }