commit c55c8b9bc0d92a551617b130297bd73bbad3e7bd parent 0277df1a779c8344c9b3d453a2d13681e8518f4b Author: Peter <peter@minskio.co.uk> Date: Tue, 6 Oct 2026 23:50:23 +0100 Enable video and image previews in lf Will probably replace with Yazi at some point Diffstat:
| M | home/lf.nix | | | 27 | ++++++++++++++++++++++++++- |
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/home/lf.nix b/home/lf.nix @@ -1,9 +1,13 @@ +{ pkgs, ... }: + { programs.lf = { enable = true; settings = { - icons = true; + # icons = true; ignorecase = true; + preview = true; + ratios = "1:2:3"; }; keybindings = { "." = "set hidden!"; @@ -13,5 +17,26 @@ "i" = "$swayimg -r *"; "gv" = "cd ~/vault"; }; + extraConfig = '' + set previewer ~/.config/lf/previewer + ''; }; + + home.file.".config/lf/previewer" = { + executable = true; + text = '' + #!/usr/bin/env bash + set -euo pipefail + file="$1" + width="$2" + height="$3" + case "$(${pkgs.file}/bin/file -Lb --mime-type -- "$file")" in + image/*) ${pkgs.chafa}/bin/chafa --format symbols --colors truecolor --size "''${width}x''${height}" --animate off --polite on -- "$file" ;; + video/*) ${pkgs.ffmpeg}/bin/ffmpeg -hide_banner -loglevel error -i "$file" -vf "thumbnail=100" -frames:v 1 -f image2pipe -c:v mjpeg -q:v 3 pipe:1 | ${pkgs.chafa}/bin/chafa --format symbols --colors truecolor --size "''${width}x''${height}" --polite on --animate off - ;; + text/*) ${pkgs.bat}/bin/bat --color=always --style=numbers --pager=never --line-range ":$((height * 2))" -- "$file" ;; + *) ${pkgs.file}/bin/file -Lb -- "$file" ;; + esac + ''; + }; + }