nix-configs

Personal NixOS and home-manager configuration files
Log | Files | Refs

lf.nix (1589B)


      1 { pkgs, ... }:
      2 
      3 {
      4   programs.lf = {
      5     enable = true;
      6     settings = {
      7       # icons = true;
      8       ignorecase = true;
      9       preview = true;
     10       ratios = "1:2:3";
     11     };
     12     keybindings = {
     13       "." = "set hidden!";
     14       "<delete>" = "delete";
     15       "<enter>" = "shell";
     16       "d" = "delete";
     17       "i" = "$swayimg -r *";
     18       "j" = "fzf-jump";
     19       "gv" = "cd ~/vault";
     20       "<esc>" = "quit";
     21       "Q" = "quit";
     22     };
     23     extraConfig = ''
     24       set previewer ~/.config/lf/previewer
     25       cmd fzf-jump ''${{
     26         dir=$(find . -type d -name .git -prune -o -type d -print | fzf --prompt='Directory: ') || exit
     27         [ -n "$dir" ] || exit
     28         lf -remote "send $id cd \"$PWD/$dir\""
     29       }}
     30     '';
     31   };
     32 
     33   home.file.".config/lf/previewer" = {
     34     executable = true;
     35     text = ''
     36     #!/usr/bin/env bash
     37       set -euo pipefail
     38       file="$1"
     39       width="$2"
     40       height="$3"
     41       case "$(${pkgs.file}/bin/file -Lb --mime-type -- "$file")" in
     42       image/*) ${pkgs.chafa}/bin/chafa --format symbols --colors truecolor --size "''${width}x''${height}" --animate off --polite on -- "$file" ;;
     43       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 - ;;
     44       text/*) ${pkgs.bat}/bin/bat --color=always  --style=numbers --pager=never --line-range ":$((height * 2))" -- "$file" ;;
     45       *) ${pkgs.file}/bin/file -Lb -- "$file" ;;
     46       esac
     47     '';
     48   };
     49 
     50 }