# modules/home/yazi.nix — yazi, the terminal file manager, with previews.
#
# Pictures preview inline in kitty (its graphics protocol; yazi draws them
# itself, nothing else needed), video frames via ffmpeg, PDFs via poppler,
# SVG via resvg, archives via 7z, JSON via jq, code with syntax colours, and
# the rest as text. Enter / l on a file opens it: images in imv, video and
# audio in mpv, PDFs and books in zathura, text in $EDITOR, anything else via
# xdg-open; o shows every opener. The toolbox's zimg/zbook/comx/gamex/dux
# are offered where they apply (they live in ~/.local/bin).
#
# y start yazi and cd to where you left it (zsh wrapper)
# T maximise the preview pane (toggle-pane) ! shell here
# <C-e>/<C-y> scroll the preview . toggle hidden
# l / Enter smart-enter: open a file, enter a directory
# Theme: Rosé Pine (modules/home/yazi/flavors). Git status marks via the git plugin.
{ ... }:
let theme = import ../_palette.nix; in
{
flake.homeModules.yazi =
{ pkgs, ... }:
{
programs.yazi = {
enable = true;
enableZshIntegration = true;
shellWrapperName = "y";
extraPackages = with pkgs; [
ffmpeg
poppler-utils
imagemagick
resvg
p7zip
jq
fd
ripgrep
fzf
zoxide
file
mediainfo
imv
];
settings = {
mgr = {
show_hidden = false;
show_symlink = true;
sort_by = "natural";
sort_sensitive = false;
sort_dir_first = true;
linemode = "size";
scrolloff = 5;
};
preview = {
max_width = 1600;
max_height = 1600;
image_delay = 20;
image_filter = "lanczos3";
image_quality = 90;
wrap = "yes";
};
opener = {
edit = [ { run = ''${EDITOR:-nvim} "$@"''; desc = "Edit"; block = true; for = "unix"; } ];
open = [ { run = ''xdg-open "$1"''; desc = "Open (system default)"; orphan = true; for = "unix"; } ];
view-image = [
{ run = ''imv "$@"''; desc = "View (imv)"; orphan = true; for = "unix"; }
{ run = ''zimg "$1"''; desc = "View in zathura (zimg)"; orphan = true; for = "unix"; }
{ run = ''xdg-open "$1"''; desc = "Open (system default)"; orphan = true; for = "unix"; }
];
play = [
{ run = ''mpv "$@"''; desc = "Play (mpv)"; orphan = true; for = "unix"; }
{ run = ''mpv --no-video "$@"''; desc = "Play audio only (mpv)"; block = true; for = "unix"; }
];
open-pdf = [
{ run = ''zathura "$@"''; desc = "Open (zathura)"; orphan = true; for = "unix"; }
{ run = ''xdg-open "$1"''; desc = "Open (system default)"; orphan = true; for = "unix"; }
];
open-book = [
{ run = ''zbook "$1"''; desc = "Read in zathura (zbook)"; orphan = true; for = "unix"; }
{ run = ''zathura "$@"''; desc = "Open (zathura)"; orphan = true; for = "unix"; }
];
open-comic = [
{ run = ''comx "$1"''; desc = "Guided view (comx)"; orphan = true; for = "unix"; }
{ run = ''zbook "$1"''; desc = "Panels in zathura (zbook)"; orphan = true; for = "unix"; }
{ run = ''7z x -y "$1"''; desc = "Extract here (7z)"; block = true; for = "unix"; }
];
extract = [ { run = ''7z x -y "$1"''; desc = "Extract here (7z)"; for = "unix"; } ];
run-exe = [
{ run = ''gamex run "$1"''; desc = "Run (gamex, dGPU)"; block = true; for = "unix"; }
{ run = ''gamex proton "$1"''; desc = "Run with Proton-GE"; block = true; for = "unix"; }
];
};
open = {
rules = [
{ mime = "image/gif"; use = [ "view-image" "open" ]; }
{ mime = "image/*"; use = [ "view-image" "open" ]; }
{ mime = "video/*"; use = [ "play" "open" ]; }
{ mime = "audio/*"; use = [ "play" "open" ]; }
{ mime = "application/pdf"; use = [ "open-pdf" "open" ]; }
{ mime = "application/epub+zip"; use = [ "open-book" "open" ]; }
{ url = "*.cbz"; use = [ "open-comic" "extract" ]; }
{ url = "*.cbr"; use = [ "open-comic" "extract" ]; }
{ url = "*.exe"; use = [ "run-exe" "open" ]; }
{ mime = "application/{zip,gzip,x-tar,x-bzip*,x-7z-compressed,x-rar,x-xz,zstd}"; use = [ "extract" "open" ]; }
{ mime = "inode/directory"; use = [ "edit" "open" ]; }
{ mime = "text/*"; use = [ "edit" "open" ]; }
{ mime = "application/{json,toml,x-ndjson,javascript,x-sh,x-shellscript,xml}"; use = [ "edit" "open" ]; }
{ mime = "*"; use = [ "open" "edit" ]; }
];
};
};
keymap.mgr.prepend_keymap = [
{ on = [ "!" ]; run = ''shell "$SHELL" --block''; desc = "Open a shell here"; }
{ on = [ "<C-e>" ]; run = "seek 5"; desc = "Scroll preview down"; }
{ on = [ "<C-y>" ]; run = "seek -5"; desc = "Scroll preview up"; }
{ on = [ "l" ]; run = "plugin smart-enter"; desc = "Enter directory or open file"; }
{ on = [ "<Enter>" ]; run = "plugin smart-enter"; desc = "Enter directory or open file"; }
{ on = [ "T" ]; run = "plugin toggle-pane max-preview"; desc = "Maximise the preview"; }
{ on = [ "u" "d" ]; run = "shell -- dux %h %s"; desc = "Copy file(s) to the clipboard as a paste-able file"; }
];
plugins = with pkgs.yaziPlugins; {
inherit full-border git smart-enter toggle-pane;
};
flavors.rose-pine = if theme.name == "rose-pine" then ./yazi/flavors/rose-pine.yazi else
pkgs.runCommand "${theme.name}-yazi" { } ''
mkdir -p "$out"
cp -r ${./yazi/flavors/rose-pine.yazi}/. "$out/"
chmod -R u+w "$out"
cp ${pkgs.writeText "flavor.toml" (theme.render (builtins.readFile ./yazi/flavors/rose-pine.yazi/flavor.toml))} "$out/flavor.toml"
cp ${pkgs.writeText "tmtheme.xml" (theme.render (builtins.readFile ./yazi/flavors/rose-pine.yazi/tmtheme.xml))} "$out/tmtheme.xml"
'';
theme.flavor = {
dark = "rose-pine";
light = "rose-pine";
};
initLua = ''
require("full-border"):setup()
require("git"):setup()
'';
};
}
;
}