From 8869dfb62a38b678279ff328bea93737f4c8a740 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Tue, 8 Jul 2025 23:08:47 +0200 Subject: [PATCH] Modules: Add yazi module --- home/modules/default.nix | 3 + home/modules/yazi/default.nix | 218 ++++++++++++++++++++++++++++++++++ home/modules/yazi/options.nix | 7 ++ 3 files changed, 228 insertions(+) create mode 100644 home/modules/yazi/default.nix create mode 100644 home/modules/yazi/options.nix diff --git a/home/modules/default.nix b/home/modules/default.nix index 3a9a7baf..9f47db45 100644 --- a/home/modules/default.nix +++ b/home/modules/default.nix @@ -3,6 +3,7 @@ # Obsolete modules are kept in "1_deprecated" for reference. # My own HM modules + ./beets ./chromium ./color ./docs @@ -12,12 +13,14 @@ ./hyprland ./hyprpanel ./kitty + ./mpd ./neovim ./nnn ./paths ./rmpc ./rofi ./waybar + ./yazi ./zathura # HM modules imported from the flake inputs diff --git a/home/modules/yazi/default.nix b/home/modules/yazi/default.nix new file mode 100644 index 00000000..18c40abc --- /dev/null +++ b/home/modules/yazi/default.nix @@ -0,0 +1,218 @@ +{ + config, + nixosConfig, + lib, + mylib, + pkgs, + ... +}: let + inherit (config.modules) yazi; +in { + options.modules.yazi = import ./options.nix {inherit lib mylib;}; + + config = lib.mkIf yazi.enable { + programs.yazi = { + enable = true; + enableFishIntegration = config.modules.fish.enable; + shellWrapperName = "y"; + + plugins = { + inherit (pkgs.yaziPlugins) chmod diff full-border git lazygit mount ouch rsync starship sudo; # smar-paste + }; + + initLua = '' + -- Load plugins + require("full-border"):setup() + require("starship"):setup() + 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 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) + ''; + + # https://yazi-rs.github.io/docs/configuration/yazi + # "$n": The n-th selected file (1...n) + # "$@": All selected files + # "$0": The hovered file + settings = { + mgr = { + show_hidden = false; + }; + + # Associate mimetypes with edit/open/play actions + # open = {}; + + # Configure programs to edit/open/play files + opener = { + play = [ + { + run = ''vlc "$@"''; + orphan = true; + desc = "Play selection"; + } + ]; + edit = [ + { + run = ''$EDITOR "$@"''; + block = true; + desc = "Edit selection"; + } + ]; + open = [ + { + run = ''xdg-open "$@"''; + desc = "Open selection"; + } + ]; + extract = [ + { + run = ''ouch decompress -y "$@"''; + desc = "Extract selection"; + } + ]; + }; + + preview = { + max_width = 1000; + max_height = 1000; + }; + + plugin.prepend_fetchers = [ + { + id = "git"; + name = "*"; + run = "git"; + } + { + id = "git"; + name = "*/"; + run = "git"; + } + ]; + + plugin.prepend_previewers = [ + { + 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/x-xz"; + run = "ouch"; + } + { + mime = "application/xz"; + run = "ouch"; + } + ]; + }; + + keymap = { + input.prepend_keymap = [ + { + # Don't exit vi mode on , but close the input + on = ""; + run = "close"; + desc = "Cancel input"; + } + ]; + + mgr.prepend_keymap = [ + { + on = ["" "m"]; + run = "plugin mount"; + desc = "Manage device mounts"; + } + { + on = ["" "c"]; + run = "plugin chmod"; + desc = "Chmod selection"; + } + { + on = ["" "g"]; + run = "plugin lazygit"; + desc = "Run LazyGit"; + } + { + on = ["" "a"]; + run = "plugin ouch"; + desc = "Add selection to archive"; + } + { + on = ["" "d"]; + run = ''shell -- ripdrag -a -n "$@"''; + desc = "Drag & drop selection"; + } + { + on = ["" "D"]; + run = "plugin diff"; + desc = "Diff the selected with the hovered file"; + } + { + on = ["" "r"]; + run = "plugin rsync"; + desc = "Copy files using rsync"; + } + + { + on = "!"; + run = ''shell "$SHELL" --block''; + desc = "Open $SHELL here"; + } + { + on = "y"; + run = [''shell -- for path in "$@"; do echo "file://$path"; done | wl-copy -t text/uri-list'' "yank"]; + desc = "Copy files to system clipboard on yank"; + } + # { + # on = "p"; + # run = "plugin smart-paste"; + # desc = "Paste into hovered directory or CWD"; + # } + { + on = "d"; + run = "remove --permanently"; + desc = "Delete selection"; + } + ]; + }; + }; + }; +} diff --git a/home/modules/yazi/options.nix b/home/modules/yazi/options.nix new file mode 100644 index 00000000..f7f80281 --- /dev/null +++ b/home/modules/yazi/options.nix @@ -0,0 +1,7 @@ +{ + lib, + mylib, + ... +}: { + enable = lib.mkEnableOption "Enable the yazi terminal file manager"; +}