about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-30 22:31:27 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-30 22:31:27 +0100
commit528f99a42ad15db3a43dd26f07cb1c61b4249647 (patch)
treebcf64ad2f2ee78d71b4bf632cf03b846dbad5ec6
parentbuild(.envrc): Remove git fetch (diff)
downloadnixos-config-528f99a42ad15db3a43dd26f07cb1c61b4249647.zip
fix(modules/lf/ctpv/xxd): Use unlimited length when piped to less
-rw-r--r--modules/by-name/lf/lf/ctpv/default.nix15
-rw-r--r--modules/by-name/lf/lf/ctpv/helpers.sh14
-rw-r--r--modules/by-name/lf/lf/module.nix9
3 files changed, 27 insertions, 11 deletions
diff --git a/modules/by-name/lf/lf/ctpv/default.nix b/modules/by-name/lf/lf/ctpv/default.nix
index a7d6927a..e25fa344 100644
--- a/modules/by-name/lf/lf/ctpv/default.nix
+++ b/modules/by-name/lf/lf/ctpv/default.nix
@@ -1,8 +1,8 @@
 {
-  pkgs,
   sysLib,
   lib,
   config,
+  pkgs,
   ...
 }: let
   functionCall = {
@@ -151,6 +151,8 @@ in {
       default = config.home-manager.users.soispha.xdg.dataHome;
     };
 
+    package = lib.mkPackageOption pkgs "ctpv" {};
+
     # TODO: This is necessary, as the `./prev` dir is imported separately and as such
     # cannot access the `./helpers.sh` file in it's parent directory.
     # This separate import should ideally be removed. <2024-12-15>
@@ -182,6 +184,17 @@ in {
     xdg.configFile = {
       "ctpv/config".text = cfg.ctpv.extraConfigPre + "\n" + (mkConfigFile cfg.ctpv.previewers);
     };
+
+    programs.lf = {
+      keybindings.i = ''$CTPV_LESS_PREVIEWER=true ${lib.getExe cfg.ctpv.package} "$f" | less -R'';
+      settings.previewer = lib.getExe cfg.ctpv.package;
+
+      extraConfig = ''
+        &${lib.getExe cfg.ctpv.package} -s $id
+        cmd on-quit %${lib.getExe cfg.ctpv.package} -e $id
+        set cleaner ${lib.getExe' cfg.ctpv.package "ctpvclear"}
+      '';
+    };
   };
 }
 # TODO: Add these. <2024-12-08>
diff --git a/modules/by-name/lf/lf/ctpv/helpers.sh b/modules/by-name/lf/lf/ctpv/helpers.sh
index c28defce..6dc7fee6 100644
--- a/modules/by-name/lf/lf/ctpv/helpers.sh
+++ b/modules/by-name/lf/lf/ctpv/helpers.sh
@@ -59,7 +59,19 @@ preview_xxd() {
     # This has been derived mathematically.
     octet_columns=$(((2 * w - 22) / 7))
 
+    if [ -n "$CTPV_LESS_PREVIEWER" ]; then
+        __base_xxd_preview "$1"
+    else
+        __base_xxd_preview "$1" -len "$((h * octet_columns))"
+    fi
+}
+
+# This should only be called from `preview_xxd`, because it needs the `octet_columns` var
+__base_xxd_preview() {
+    __file="$1"
+    shift 1
+
     # -R: colorization
     # -u: Uppercase letters for hexadecimal
-    xxd -R always -u -cols "$octet_columns" -len "$((h * octet_columns))" -- "$1"
+    xxd -R always -u -cols "$octet_columns" "$@" -- "$__file"
 }
diff --git a/modules/by-name/lf/lf/module.nix b/modules/by-name/lf/lf/module.nix
index 1c587c9d..6dc8e919 100644
--- a/modules/by-name/lf/lf/module.nix
+++ b/modules/by-name/lf/lf/module.nix
@@ -54,10 +54,6 @@ in {
 
         inherit commands keybindings;
 
-        previewer = {
-          keybinding = "i";
-          source = lib.getExe' pkgs.ctpv "ctpv";
-        };
         settings = {
           # Always keep the server running
           autoquit = false;
@@ -83,11 +79,6 @@ in {
           shellopts = "-eu"; # e: exit on error; u: error for unset variables
         };
         extraConfig = ''
-          # Keep these here, to ensure they are the last lines of the lfrc file.
-          &${pkgs.ctpv}/bin/ctpv -s $id
-          cmd on-quit %${lib.getExe' pkgs.ctpv "ctpv"} -e $id
-          set cleaner ${pkgs.ctpv}/bin/ctpvclear
-
           # Dynamically generate the cd mappings.
           # This code dependends on the fact, that the lf server was started previously
           # and keep running through `autoquit = false`.