about summary refs log tree commit diff stats
path: root/modules/by-name/lf
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-11-25 16:20:31 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-11-25 16:20:31 +0100
commita44ac5a118c08247abd65b5b2678ac2ad6f94597 (patch)
tree67669979df9e4b65602667fc991cb958b277294f /modules/by-name/lf
parentfix(modules/lf/ctpv/prev/glow): Force glow to colorize the output (diff)
downloadnixos-config-a44ac5a118c08247abd65b5b2678ac2ad6f94597.tar.gz
nixos-config-a44ac5a118c08247abd65b5b2678ac2ad6f94597.zip
fix(modules/lf/ctpv/): Support color output, by simulating a interactive shell
Diffstat (limited to 'modules/by-name/lf')
-rw-r--r--modules/by-name/lf/lf/ctpv/default.nix18
-rw-r--r--modules/by-name/lf/lf/ctpv/helpers.sh13
-rw-r--r--modules/by-name/lf/lf/ctpv/prev/any.sh2
-rw-r--r--modules/by-name/lf/lf/ctpv/prev/audio.sh4
-rw-r--r--modules/by-name/lf/lf/ctpv/prev/glow.sh2
-rw-r--r--modules/by-name/lf/lf/ctpv/prev/gpg.sh2
6 files changed, 33 insertions, 8 deletions
diff --git a/modules/by-name/lf/lf/ctpv/default.nix b/modules/by-name/lf/lf/ctpv/default.nix
index 29f4f8ba..b47e03bd 100644
--- a/modules/by-name/lf/lf/ctpv/default.nix
+++ b/modules/by-name/lf/lf/ctpv/default.nix
@@ -14,7 +14,19 @@
       inherit name;
       src = ./prev/${name}.sh;
       keepPath = false;
-      dependencies = dependencies ++ (builtins.attrValues {inherit (pkgs) dash coreutils;});
+      dependencies =
+        dependencies
+        ++ (
+          with pkgs; [
+            dash
+            coreutils
+            # Dependencies of the helpers.sh script
+            chafa
+            gnused
+            gnugrep
+            unixtools.script
+          ]
+        );
       inherit replacementStrings;
     }
     + "/bin/${name}";
@@ -66,8 +78,7 @@
     extensions = lib.strings.concatStringsSep " " (builtins.map (val: ''."${val}"'') extension_matches);
     mimes = lib.strings.concatStringsSep " " (
       if escape
-      then
-        builtins.map mkMimePath mime_matches
+      then builtins.map mkMimePath mime_matches
       else mime_matches
     );
     function = functionCall {
@@ -162,7 +173,6 @@ in
     image = {
       mime_matches = ["image/*"];
       dependencies = [
-        pkgs.chafa
       ];
     };
 
diff --git a/modules/by-name/lf/lf/ctpv/helpers.sh b/modules/by-name/lf/lf/ctpv/helpers.sh
index 50a0e7cd..379a98a4 100644
--- a/modules/by-name/lf/lf/ctpv/helpers.sh
+++ b/modules/by-name/lf/lf/ctpv/helpers.sh
@@ -54,3 +54,16 @@ convert_and_show_image() {
 isBinary() {
     LC_ALL=C LC_MESSAGES=C grep --with-filename --max-count=1 '^' "$1" 2>&1 | grep --quiet 'binary file matches$'
 }
+
+hide_script_env() {
+    cmd=""
+    for part in "$@"; do
+        if [ "$cmd" = "" ]; then
+            cmd="'$part'"
+        else
+            cmd="$cmd '$part'"
+        fi
+    done
+
+    script --command "$cmd" --quiet --return /dev/null
+}
diff --git a/modules/by-name/lf/lf/ctpv/prev/any.sh b/modules/by-name/lf/lf/ctpv/prev/any.sh
index 7209fccb..bb25d90b 100644
--- a/modules/by-name/lf/lf/ctpv/prev/any.sh
+++ b/modules/by-name/lf/lf/ctpv/prev/any.sh
@@ -54,5 +54,5 @@ if exiftool "$f" >/dev/null 2>&1; then
     exiftool -- "$f"
 else
     # `exiftool` did not recognize the file.
-    xxd -- "$f"
+    hide_script_env xxd -- "$f"
 fi
diff --git a/modules/by-name/lf/lf/ctpv/prev/audio.sh b/modules/by-name/lf/lf/ctpv/prev/audio.sh
index a828ab6c..c5abc646 100644
--- a/modules/by-name/lf/lf/ctpv/prev/audio.sh
+++ b/modules/by-name/lf/lf/ctpv/prev/audio.sh
@@ -11,10 +11,10 @@ cache_f="$cache_f"
 . %HELPERS
 
 audio() {
-    ffmpegthumbnailer "-i$f" -s0 -q5 -t10 "-o$cache_f" 2>/dev/null
+    ffmpegthumbnailer -i "$f" -s 0 -q 5 -t 10 -o "$cache_f" 2>/dev/null
 }
 
-x="$(ffmpeg -hide_banner "-i$f" 2>&1)"
+x="$(ffmpeg -hide_banner -i "$f" 2>&1)"
 printf '%s\n' "$x"
 y=$((y + $(printf '%s\n' "$x" | wc -l)))
 
diff --git a/modules/by-name/lf/lf/ctpv/prev/glow.sh b/modules/by-name/lf/lf/ctpv/prev/glow.sh
index c77bfa41..301fe675 100644
--- a/modules/by-name/lf/lf/ctpv/prev/glow.sh
+++ b/modules/by-name/lf/lf/ctpv/prev/glow.sh
@@ -12,4 +12,6 @@ w="$w"
 
 # Specify the style, to force `glow` to output colors.
 # tracking issue: https://github.com/charmbracelet/glow/issues/654
+# We can't use `hide_script_env` because of some bespoke reason. (It just forces glow to
+# run for ever and then return garbage)
 glow --style dark --width "$w" "$f"
diff --git a/modules/by-name/lf/lf/ctpv/prev/gpg.sh b/modules/by-name/lf/lf/ctpv/prev/gpg.sh
index 72cca3a6..f162c565 100644
--- a/modules/by-name/lf/lf/ctpv/prev/gpg.sh
+++ b/modules/by-name/lf/lf/ctpv/prev/gpg.sh
@@ -10,4 +10,4 @@ w="$w"
 
 . %HELPERS
 
-sq inspect -- "$f" 2>&1
+hide_script_env sq inspect -- "$f"