yazi.nix (5896B)
1 # modules/home/yazi.nix — yazi, the terminal file manager, with previews. 2 # 3 # Pictures preview inline in kitty (its graphics protocol; yazi draws them 4 # itself, nothing else needed), video frames via ffmpeg, PDFs via poppler, 5 # SVG via resvg, archives via 7z, JSON via jq, code with syntax colours, and 6 # the rest as text. Enter / l on a file opens it: images in imv, video and 7 # audio in mpv, PDFs and books in zathura, text in $EDITOR, anything else via 8 # xdg-open; o shows every opener. The toolbox's zimg/zbook/comx/gamex/dux 9 # are offered where they apply (they live in ~/.local/bin). 10 # 11 # y start yazi and cd to where you left it (zsh wrapper) 12 # T maximise the preview pane (toggle-pane) ! shell here 13 # <C-e>/<C-y> scroll the preview . toggle hidden 14 # l / Enter smart-enter: open a file, enter a directory 15 # Theme: Rosé Pine (modules/home/yazi/flavors). Git status marks via the git plugin. 16 { ... }: 17 { 18 flake.homeModules.yazi = 19 { pkgs, ... }: 20 { 21 programs.yazi = { 22 enable = true; 23 enableZshIntegration = true; 24 shellWrapperName = "y"; 25 extraPackages = with pkgs; [ 26 ffmpeg 27 poppler-utils 28 imagemagick 29 resvg 30 p7zip 31 jq 32 fd 33 ripgrep 34 fzf 35 zoxide 36 file 37 mediainfo 38 imv 39 ]; 40 41 settings = { 42 mgr = { 43 show_hidden = false; 44 show_symlink = true; 45 sort_by = "natural"; 46 sort_sensitive = false; 47 sort_dir_first = true; 48 linemode = "size"; 49 scrolloff = 5; 50 }; 51 preview = { 52 max_width = 1600; 53 max_height = 1600; 54 image_delay = 20; 55 image_filter = "lanczos3"; 56 image_quality = 90; 57 wrap = "yes"; 58 }; 59 opener = { 60 edit = [ { run = ''${EDITOR:-nvim} "$@"''; desc = "Edit"; block = true; for = "unix"; } ]; 61 open = [ { run = ''xdg-open "$1"''; desc = "Open (system default)"; orphan = true; for = "unix"; } ]; 62 view-image = [ 63 { run = ''imv "$@"''; desc = "View (imv)"; orphan = true; for = "unix"; } 64 { run = ''zimg "$1"''; desc = "View in zathura (zimg)"; orphan = true; for = "unix"; } 65 { run = ''xdg-open "$1"''; desc = "Open (system default)"; orphan = true; for = "unix"; } 66 ]; 67 play = [ 68 { run = ''mpv "$@"''; desc = "Play (mpv)"; orphan = true; for = "unix"; } 69 { run = ''mpv --no-video "$@"''; desc = "Play audio only (mpv)"; block = true; for = "unix"; } 70 ]; 71 open-pdf = [ 72 { run = ''zathura "$@"''; desc = "Open (zathura)"; orphan = true; for = "unix"; } 73 { run = ''xdg-open "$1"''; desc = "Open (system default)"; orphan = true; for = "unix"; } 74 ]; 75 open-book = [ 76 { run = ''zbook "$1"''; desc = "Read in zathura (zbook)"; orphan = true; for = "unix"; } 77 { run = ''zathura "$@"''; desc = "Open (zathura)"; orphan = true; for = "unix"; } 78 ]; 79 open-comic = [ 80 { run = ''comx "$1"''; desc = "Guided view (comx)"; orphan = true; for = "unix"; } 81 { run = ''zbook "$1"''; desc = "Panels in zathura (zbook)"; orphan = true; for = "unix"; } 82 { run = ''7z x -y "$1"''; desc = "Extract here (7z)"; block = true; for = "unix"; } 83 ]; 84 extract = [ { run = ''7z x -y "$1"''; desc = "Extract here (7z)"; for = "unix"; } ]; 85 run-exe = [ 86 { run = ''gamex run "$1"''; desc = "Run (gamex, dGPU)"; block = true; for = "unix"; } 87 { run = ''gamex proton "$1"''; desc = "Run with Proton-GE"; block = true; for = "unix"; } 88 ]; 89 }; 90 open = { 91 rules = [ 92 { mime = "image/gif"; use = [ "view-image" "open" ]; } 93 { mime = "image/*"; use = [ "view-image" "open" ]; } 94 { mime = "video/*"; use = [ "play" "open" ]; } 95 { mime = "audio/*"; use = [ "play" "open" ]; } 96 { mime = "application/pdf"; use = [ "open-pdf" "open" ]; } 97 { mime = "application/epub+zip"; use = [ "open-book" "open" ]; } 98 { name = "*.cbz"; use = [ "open-comic" "extract" ]; } 99 { name = "*.cbr"; use = [ "open-comic" "extract" ]; } 100 { name = "*.exe"; use = [ "run-exe" "open" ]; } 101 { mime = "application/{zip,gzip,x-tar,x-bzip*,x-7z-compressed,x-rar,x-xz,zstd}"; use = [ "extract" "open" ]; } 102 { mime = "inode/directory"; use = [ "edit" "open" ]; } 103 { mime = "text/*"; use = [ "edit" "open" ]; } 104 { mime = "application/{json,toml,x-ndjson,javascript,x-sh,x-shellscript,xml}"; use = [ "edit" "open" ]; } 105 { mime = "*"; use = [ "open" "edit" ]; } 106 ]; 107 }; 108 }; 109 110 keymap.mgr.prepend_keymap = [ 111 { on = [ "!" ]; run = ''shell "$SHELL" --block''; desc = "Open a shell here"; } 112 { on = [ "<C-e>" ]; run = "seek 5"; desc = "Scroll preview down"; } 113 { on = [ "<C-y>" ]; run = "seek -5"; desc = "Scroll preview up"; } 114 { on = [ "l" ]; run = "plugin smart-enter"; desc = "Enter directory or open file"; } 115 { on = [ "<Enter>" ]; run = "plugin smart-enter"; desc = "Enter directory or open file"; } 116 { on = [ "T" ]; run = "plugin toggle-pane max-preview"; desc = "Maximise the preview"; } 117 { on = [ "u" "d" ]; run = "shell -- dux %h %s"; desc = "Copy file(s) to the clipboard as a paste-able file"; } 118 ]; 119 120 plugins = with pkgs.yaziPlugins; { 121 inherit full-border git smart-enter toggle-pane; 122 }; 123 flavors.rose-pine = ./yazi/flavors/rose-pine.yazi; 124 theme.flavor = { 125 dark = "rose-pine"; 126 light = "rose-pine"; 127 }; 128 initLua = '' 129 require("full-border"):setup() 130 require("git"):setup() 131 ''; 132 }; 133 } 134 ; 135 }