From 118e70dd7493f781175143b7ba4b7f335ba8b69a Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 24 Nov 2024 20:14:43 +0100 Subject: fix(modules/lf/ctpv): Improve ctpv config file generation --- modules/by-name/lf/lf/ctpv/default.nix | 59 +++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 8 deletions(-) (limited to 'modules/by-name') diff --git a/modules/by-name/lf/lf/ctpv/default.nix b/modules/by-name/lf/lf/ctpv/default.nix index 9667bc48..29f4f8ba 100644 --- a/modules/by-name/lf/lf/ctpv/default.nix +++ b/modules/by-name/lf/lf/ctpv/default.nix @@ -19,7 +19,37 @@ } + "/bin/${name}"; + default_previews = [ + "any" + "atool" + "audio" + "bat" + "cat" + "colordiff" + "delta" + "diff_so_fancy" + "elinks" + "font" + "glow" + "gpg" + "highlight" + "image" + "jq" + "libreoffice" + "ls" + "lynx" + "mdcat" + "pdf" + "source_highlight" + "svg" + "symlink" + "torrent" + "video" + "w3m" + ]; + mkPreview = name: { + escape ? true, mime_matches ? [], extension_matches ? [], priority ? 0, @@ -34,17 +64,28 @@ assert builtins.length split == 2; ''"${rhs}"/"${lhs}"''; extensions = lib.strings.concatStringsSep " " (builtins.map (val: ''."${val}"'') extension_matches); - mimes = lib.strings.concatStringsSep " " (builtins.map mkMimePath mime_matches); + mimes = lib.strings.concatStringsSep " " ( + if escape + then + builtins.map mkMimePath mime_matches + else mime_matches + ); function = functionCall { inherit name dependencies; replacementStrings = {HELPERS = ./helpers.sh;} // replacementStrings; }; - in '' - preview ${name} ${extensions} ${mimes} {{ - ${function} - }} - priority ${name} ${builtins.toString priority} - ''; + in + lib.optionalString (builtins.elem name default_previews) "remove ${name}\n" + + '' + preview ${name} ${extensions} ${mimes} {{ + ${function} + + # Always exit with success, when the function didn't exit, + # to ensure that error messages come through + true + }} + priority ${name} ${builtins.toString priority} + ''; mkRemove = name: '' remove ${name} @@ -72,10 +113,12 @@ in "w3m" = null; any = { + escape = false; + mime_matches = ["*/*"]; priority = -1; dependencies = [ pkgs.exiftool - pkgs.vim # For xxd + pkgs.tinyxxd # For xxd ]; }; -- cgit 1.4.1