From 53d49dbebccfcbd68f360b067af9a69e1a130a1f Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sat, 14 Dec 2024 14:56:55 +0100 Subject: feat(modules/lf/ctpv): Rework as module with autoloading --- modules/by-name/lf/lf/ctpv/default.nix | 458 ++++++++------------- modules/by-name/lf/lf/ctpv/helpers.sh | 23 +- modules/by-name/lf/lf/ctpv/prev/any.sh | 81 ++-- .../lf/lf/ctpv/prev/application/archive/atool.sh | 11 + .../lf/ctpv/prev/application/archive/default.nix | 89 ++++ .../lf/lf/ctpv/prev/application/dll/default.nix | 14 + .../by-name/lf/lf/ctpv/prev/application/dll/dll.sh | 19 + .../lf/lf/ctpv/prev/application/epub/default.nix | 14 + .../lf/lf/ctpv/prev/application/epub/epub.sh | 27 ++ .../lf/lf/ctpv/prev/application/pdf/default.nix | 12 + .../by-name/lf/lf/ctpv/prev/application/pdf/pdf.sh | 22 + .../lf/lf/ctpv/prev/application/pgp/default.nix | 17 + .../by-name/lf/lf/ctpv/prev/application/pgp/pgp.sh | 13 + .../lf/lf/ctpv/prev/application/sqlite/default.nix | 13 + .../lf/lf/ctpv/prev/application/sqlite/sqlite.sh | 22 + .../ctpv/prev/application/x-bittorrent/default.nix | 11 + .../ctpv/prev/application/x-bittorrent/torrent.sh | 13 + modules/by-name/lf/lf/ctpv/prev/atool.sh | 11 - modules/by-name/lf/lf/ctpv/prev/audio.sh | 21 - modules/by-name/lf/lf/ctpv/prev/audio/audio.sh | 21 + modules/by-name/lf/lf/ctpv/prev/audio/default.nix | 12 + modules/by-name/lf/lf/ctpv/prev/bat.sh | 19 - modules/by-name/lf/lf/ctpv/prev/default.nix | 23 ++ modules/by-name/lf/lf/ctpv/prev/delta.sh | 11 - modules/by-name/lf/lf/ctpv/prev/elinks.sh | 18 - modules/by-name/lf/lf/ctpv/prev/font.sh | 18 - modules/by-name/lf/lf/ctpv/prev/font/default.nix | 17 + modules/by-name/lf/lf/ctpv/prev/font/font.sh | 18 + modules/by-name/lf/lf/ctpv/prev/glow.sh | 17 - modules/by-name/lf/lf/ctpv/prev/gpg.sh | 13 - modules/by-name/lf/lf/ctpv/prev/image.sh | 11 - modules/by-name/lf/lf/ctpv/prev/image/default.nix | 11 + modules/by-name/lf/lf/ctpv/prev/image/image.sh | 11 + .../lf/lf/ctpv/prev/image/svg+xml/default.nix | 12 + .../by-name/lf/lf/ctpv/prev/image/svg+xml/svg.sh | 17 + .../lf/lf/ctpv/prev/image/x-xcf/default.nix | 13 + modules/by-name/lf/lf/ctpv/prev/image/x-xcf/xcf.sh | 37 ++ modules/by-name/lf/lf/ctpv/prev/inode/default.nix | 16 + modules/by-name/lf/lf/ctpv/prev/inode/ls.sh | 15 + modules/by-name/lf/lf/ctpv/prev/inode/symlink.sh | 14 + modules/by-name/lf/lf/ctpv/prev/jq.sh | 11 - modules/by-name/lf/lf/ctpv/prev/ls.sh | 15 - modules/by-name/lf/lf/ctpv/prev/pdf.sh | 22 - .../lf/lf/ctpv/prev/remove_default_previews.nix | 30 ++ modules/by-name/lf/lf/ctpv/prev/svg.sh | 17 - modules/by-name/lf/lf/ctpv/prev/symlink.sh | 14 - modules/by-name/lf/lf/ctpv/prev/text/bat.sh | 13 + modules/by-name/lf/lf/ctpv/prev/text/default.nix | 21 + .../by-name/lf/lf/ctpv/prev/text/diff/default.nix | 12 + modules/by-name/lf/lf/ctpv/prev/text/diff/delta.sh | 11 + modules/by-name/lf/lf/ctpv/prev/text/glow.sh | 17 + .../by-name/lf/lf/ctpv/prev/text/html/default.nix | 13 + .../by-name/lf/lf/ctpv/prev/text/html/elinks.sh | 18 + .../by-name/lf/lf/ctpv/prev/text/json/default.nix | 12 + modules/by-name/lf/lf/ctpv/prev/text/json/jq.sh | 11 + modules/by-name/lf/lf/ctpv/prev/torrent.sh | 13 - modules/by-name/lf/lf/ctpv/prev/video.sh | 17 - modules/by-name/lf/lf/ctpv/prev/video/default.nix | 11 + modules/by-name/lf/lf/ctpv/prev/video/video.sh | 17 + modules/by-name/lf/lf/ctpv/prev/xcf.sh | 37 -- modules/by-name/lf/lf/module.nix | 5 +- 61 files changed, 943 insertions(+), 629 deletions(-) create mode 100644 modules/by-name/lf/lf/ctpv/prev/application/archive/atool.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/application/archive/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/application/dll/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/application/dll/dll.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/application/epub/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/application/epub/epub.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/application/pdf/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/application/pdf/pdf.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/application/pgp/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/application/pgp/pgp.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/application/sqlite/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/application/sqlite/sqlite.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/application/x-bittorrent/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/application/x-bittorrent/torrent.sh delete mode 100644 modules/by-name/lf/lf/ctpv/prev/atool.sh delete mode 100644 modules/by-name/lf/lf/ctpv/prev/audio.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/audio/audio.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/audio/default.nix delete mode 100644 modules/by-name/lf/lf/ctpv/prev/bat.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/default.nix delete mode 100644 modules/by-name/lf/lf/ctpv/prev/delta.sh delete mode 100644 modules/by-name/lf/lf/ctpv/prev/elinks.sh delete mode 100644 modules/by-name/lf/lf/ctpv/prev/font.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/font/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/font/font.sh delete mode 100644 modules/by-name/lf/lf/ctpv/prev/glow.sh delete mode 100644 modules/by-name/lf/lf/ctpv/prev/gpg.sh delete mode 100644 modules/by-name/lf/lf/ctpv/prev/image.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/image/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/image/image.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/image/svg+xml/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/image/svg+xml/svg.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/image/x-xcf/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/image/x-xcf/xcf.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/inode/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/inode/ls.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/inode/symlink.sh delete mode 100644 modules/by-name/lf/lf/ctpv/prev/jq.sh delete mode 100644 modules/by-name/lf/lf/ctpv/prev/ls.sh delete mode 100644 modules/by-name/lf/lf/ctpv/prev/pdf.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/remove_default_previews.nix delete mode 100644 modules/by-name/lf/lf/ctpv/prev/svg.sh delete mode 100644 modules/by-name/lf/lf/ctpv/prev/symlink.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/text/bat.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/text/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/text/diff/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/text/diff/delta.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/text/glow.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/text/html/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/text/html/elinks.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/text/json/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/text/json/jq.sh delete mode 100644 modules/by-name/lf/lf/ctpv/prev/torrent.sh delete mode 100644 modules/by-name/lf/lf/ctpv/prev/video.sh create mode 100644 modules/by-name/lf/lf/ctpv/prev/video/default.nix create mode 100644 modules/by-name/lf/lf/ctpv/prev/video/video.sh delete mode 100644 modules/by-name/lf/lf/ctpv/prev/xcf.sh (limited to 'modules') diff --git a/modules/by-name/lf/lf/ctpv/default.nix b/modules/by-name/lf/lf/ctpv/default.nix index f61b65f1..e89ae453 100644 --- a/modules/by-name/lf/lf/ctpv/default.nix +++ b/modules/by-name/lf/lf/ctpv/default.nix @@ -2,101 +2,68 @@ pkgs, sysLib, lib, + config, ... }: let functionCall = { name, dependencies, replacementStrings, + scriptPath, ... }: sysLib.writeShellScript { inherit name; - src = ./prev/${name}.sh; + src = scriptPath; keepPath = false; - dependencies = - dependencies - ++ ( - with pkgs; [ - dash - coreutils - # Dependencies of the helpers.sh script - chafa - gnused - gnugrep - unixtools.script - ] - ); - inherit replacementStrings; + inherit replacementStrings dependencies; } + "/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, - dependencies ? [], - replacementStrings ? {}, + matches, + priority, + dependencies, + replacementStrings, + previewer, }: let mkMimePath = val: let split = lib.strings.splitString "/" val; rhs = builtins.elemAt split 0; lhs = builtins.elemAt split 1; + + e_rhs = + if rhs == "*" + then rhs + else "\"${rhs}\""; + e_lhs = + if lhs == "*" + then lhs + else "\"${lhs}\""; in - assert builtins.length split == 2; ''"${rhs}"/"${lhs}"''; + assert builtins.length split == 2; "${e_rhs}/${e_lhs}"; - extensions = lib.strings.concatStringsSep " " (builtins.map (val: ''."${val}"'') extension_matches); - mimes = lib.strings.concatStringsSep " " ( - if escape - then builtins.map mkMimePath mime_matches - else mime_matches - ); + extensions = lib.strings.concatStringsSep " " (builtins.map (val: ''."${val}"'') matches.extension); + mimes = lib.strings.concatStringsSep " " (builtins.map mkMimePath matches.mime); function = functionCall { - inherit name dependencies; - replacementStrings = {HELPERS = ./helpers.sh;} // replacementStrings; - }; - 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} - ''; + inherit + name + dependencies + replacementStrings + ; + scriptPath = previewer; + }; + in '' + preview ${name} ${extensions} ${mimes} {{ + # When the function exits with code 127 (no command found), ctpv will treat it as + # signal to contiue with the next previewer and hide this failure. + # As we wrap them in their dependencies, they should never fail and as such we want + # to know about the problem. + + ${function} || exit 1 + }} + priority ${name} ${builtins.toString priority} + ''; mkRemove = name: '' remove ${name} @@ -110,226 +77,131 @@ then mkRemove name else mkPreview name value) attrs)); -in - mkConfigFile - { - # Remove all the default ones. - "cat" = null; - "colordiff" = null; - "diff_so_fancy" = null; - "highlight" = null; - "lynx" = null; - "mdcat" = null; - "source_highlight" = null; - "w3m" = null; - any = { - escape = false; - mime_matches = ["*/*"]; - priority = -1; - dependencies = [ - pkgs.exiftool - pkgs.tinyxxd # For xxd - ]; - }; + previewSubmodule = lib.types.submodule { + options = { + matches = { + mime = lib.mkOption { + type = lib.types.listOf (lib.types.strMatching "([a-z0-9A-Z_-]+|\\*)/([a-z0-9A-Z_.+-]+|\\*)"); + default = []; + description = "All mime types to match."; + }; + extension = lib.mkOption { + type = lib.types.listOf (lib.types.strMatching "[a-z0-9A-Z].?+"); + default = []; + description = "All extensions to match."; + }; + }; + + previewer = lib.mkOption { + type = lib.types.pathInStore; + description = "The path to the preview script or binary"; + }; + + priority = lib.mkOption { + # Priority is a c int in ctpv, so a 16 bits should be enough. + type = lib.types.ints.s16; + default = 0; + description = "The priority to use this previewer."; + }; + replacementStrings = lib.mkOption { + type = lib.types.attrsOf (lib.types.either lib.types.str lib.types.pathInStore); + default = { + HELPERS = ./helpers.sh; + }; + description = "Arbitrary strings to replace in the shell script."; + }; + dependencies = lib.mkOption { + type = lib.types.listOf lib.types.package; + default = with pkgs; [ + dash + coreutils + # Dependencies of the helpers.sh script + chafa + gnused + gnugrep + unixtools.script + ]; + description = "The packages to provide to the script"; + }; + }; + }; + + other_files = filter_nulls (import_dir ./prev); + + filter_nulls = input: + builtins.concatMap (val: + if val == null + then [] + else if builtins.isList val + then filter_nulls val + else [val]) + input; + + import_dir = path: + lib.attrsets.mapAttrsToList (file: type: + if type == "directory" + then import_dir "${path}/${file}" + else if builtins.match "[^.]+\\.nix" file != null + then "${path}/${file}" + else null) (builtins.readDir path); + + cfg = config.soispha.programs.lf; +in { + imports = other_files; + + options.soispha.programs.lf.ctpv = { + xdgDataHome = lib.mkOption { + description = '' + The directory to treat as the XDG_DATA_HOME. + ''; + type = lib.types.str; + default = config.home-manager.users.soispha.xdg.dataHome; + }; + + previewers = lib.mkOption { + description = '' + The previewers to add to the config file. + ''; + type = lib.types.attrsOf (lib.types.nullOr previewSubmodule); + default = {}; + }; + extraConfigPre = lib.mkOption { + description = '' + A string that is passed first in the config file. + ''; + type = lib.types.lines; + default = ""; + }; + }; + + config.home-manager.users.soispha = lib.mkIf cfg.enable { + xdg.configFile = { + "ctpv/config".text = cfg.ctpv.extraConfigPre + "\n" + (mkConfigFile cfg.ctpv.previewers); + }; + }; +} +# TODO: Add these. <2024-12-08> +# libreoffice = { +# extension_matches = [ +# "csv" +# "doc" +# "docx" +# "fodp" +# "fods" +# "fodt" +# "odp" +# "ods" +# "odt" +# "ppt" +# "pptx" +# "xls" +# "xlsx" +# ]; +# dependencies = [ +# pkgs.libreoffice +# ]; +# }; +# +# ) - audio = { - mime_matches = ["audio/*"]; - dependencies = [ - pkgs.ffmpegthumbnailer - pkgs.ffmpeg - ]; - }; - - delta = { - priority = 1; - mime_matches = ["text/x-diff" "text/x-patch"]; - dependencies = [ - pkgs.delta - ]; - }; - # TODO: I might want to use lynx/w3m instead <2024-11-24> - elinks = { - priority = 1; - mime_matches = ["text/html"]; - dependencies = [ - pkgs.elinks - ]; - }; - bat = { - mime_matches = ["text/*"]; - dependencies = [ - pkgs.bat - ]; - }; - - xcf = { - priority = 1; - mime_matches = ["image/x-xcf"]; - dependencies = [ - # pkgs.gimp - pkgs.exiftool - ]; - }; - svg = { - priority = 1; - mime_matches = ["image/svg+xml"]; - dependencies = [ - pkgs.imagemagick - ]; - }; - image = { - mime_matches = ["image/*"]; - dependencies = [ - ]; - }; - - jq = { - priority = 1; - mime_matches = ["application/json"]; - dependencies = [ - pkgs.jq - ]; - }; - pdf = { - priority = 1; - mime_matches = ["application/pdf"]; - dependencies = [ - pkgs.poppler_utils # for `pdftoppm` - ]; - }; - - ls = { - priority = 1; - mime_matches = ["inode/directory"]; - dependencies = []; - }; - symlink = { - priority = 1; - mime_matches = ["inode/symlink"]; - dependencies = []; - }; - - font = { - mime_matches = ["font/*"]; - dependencies = [ - pkgs.fontforge # for `fontimage` - ]; - }; - video = { - mime_matches = ["video/*"]; - dependencies = [ - pkgs.ffmpegthumbnailer - ]; - }; - - libreoffice = { - extension_matches = [ - "csv" - "doc" - "docx" - "fodp" - "fods" - "fodt" - "odp" - "ods" - "odt" - "ppt" - "pptx" - "xls" - "xlsx" - ]; - dependencies = [ - pkgs.libreoffice - ]; - }; - - atool = { - extension_matches = [ - "7z" - "Z" - "a" - "ace" - "alz" - "arc" - "arj" - "bz" - "bz2" - "cab" - "cpio" - "deb" - "gz" - "jar" - "lha" - "lrz" - "lz" - "lzh" - "lzma" - "lzo" - "rar" - "rpm" - "rz" - "t7z" - "tZ" - "tar" - "tar.7z" - "tar.Z" - "tar.bz" - "tar.bz2" - "tar.gz" - "tar.lz" - "tar.lzo" - "tar.xz" - "tbz" - "tbz2" - "tgz" - "tlz" - "txz" - "tzo" - "war" - "xz" - "zip" - ]; - dependencies = [ - pkgs.atool - - # archive tools - pkgs.file - pkgs.gnutar - pkgs.gzip - pkgs.pbzip2 - pkgs.plzip - pkgs.lzop - pkgs.xz - pkgs.zip - pkgs.unzip - pkgs.arj - pkgs.rpm - pkgs.cpio - pkgs.archiver # for arc - pkgs.p7zip - - # Unfree stuff - # pkgs.rar - # pkgs.lha - ]; - }; - glow = { - extension_matches = ["md"]; - dependencies = [ - pkgs.glow - ]; - }; - gpg = { - extension_matches = ["gpg" "asc" "key" "pgp" "sig"]; - dependencies = [ - pkgs.sequoia-sq - ]; - }; - torrent = { - extension_matches = ["torrent"]; - dependencies = [ - pkgs.transmission_4 # for `transmission-show` - ]; - }; - } diff --git a/modules/by-name/lf/lf/ctpv/helpers.sh b/modules/by-name/lf/lf/ctpv/helpers.sh index dacda766..c28defce 100644 --- a/modules/by-name/lf/lf/ctpv/helpers.sh +++ b/modules/by-name/lf/lf/ctpv/helpers.sh @@ -32,10 +32,6 @@ convert_and_show_image() { send_image "$cache_f" } -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 @@ -48,3 +44,22 @@ hide_script_env() { script --command "$cmd" --quiet --return /dev/null } + +preview_bat() { + bat \ + --color always \ + --style plain \ + --paging never \ + --terminal-width "$w" \ + --wrap character \ + -- "$1" +} + +preview_xxd() { + # This has been derived mathematically. + octet_columns=$(((2 * w - 22) / 7)) + + # -R: colorization + # -u: Uppercase letters for hexadecimal + xxd -R always -u -cols "$octet_columns" -len "$((h * octet_columns))" -- "$1" +} diff --git a/modules/by-name/lf/lf/ctpv/prev/any.sh b/modules/by-name/lf/lf/ctpv/prev/any.sh index bb25d90b..ecb18e02 100644 --- a/modules/by-name/lf/lf/ctpv/prev/any.sh +++ b/modules/by-name/lf/lf/ctpv/prev/any.sh @@ -5,54 +5,43 @@ SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH # shellcheck disable=SC2269 f="$f" +# shellcheck disable=SC2269 +w="$w" +# shellcheck disable=SC2269 +e="$e" +# shellcheck disable=SC2269 +m="$m" +# shellcheck disable=SC2269 +h="$h" + +# shellcheck disable=SC2269 +extension="$e" +# shellcheck disable=SC2269 +mime="$m" . %HELPERS -# FIXME: Fix the problem, that `???.log.gpg` won't trigger the gpg -# preview, as `cptv` thinks, the extension is `log.gpg` <2024-11-24> -# -# # Before running things on the last extension, ctpv tries to run a preview on the full -# # extension. Therefore, we need to filter these out, to allow the real display to run on -# # them. -# -# full_extension="${f#*.}" -# -# # contains(string, substring) -# # -# # Returns 0 if the specified string contains the specified substring, -# # otherwise returns 1. -# contains() { -# string="$1" -# substring="$2" -# if [ "${string#*"$substring"}" != "$string" ]; then -# return 0 # $substring is in $string -# else -# return 1 # $substring is not in $string -# fi -# } -# -# if contains "$full_extension" "."; then -# sub_extension="${full_extension#*.}" -# base_extension="${full_extension%.*}" -# -# case "$base_extension" in -# "tar") -# # delegate to the archive tool -# exit 127 -# ;; -# esac -# -# case "$sub_extension" in -# "gpg" | "sig" | "key" | "cert" | "asc") -# # delegate to the gpg tool -# exit 127 -# ;; -# esac -# fi - -if exiftool "$f" >/dev/null 2>&1; then - exiftool -- "$f" +is_not_printable() { + grep --text --quiet '[^[:print:]]' "$1" +} + +case "$mime" in +"application/octet-stream") + # Ignore this mime type in the warning, as can't really find a good way to preview it. + ;; + +*) + echo "(ctpv did not recognize this file, with extension: '$extension' and mime: '$mime')" + + directory_storage="%STORAGE_DIRECTORY/$mime" + mkdir --parents "$(dirname "%STORAGE_DIRECTORY/$mime")" + + printf "%s -- %s\n" "$f" "$extension" >>"$directory_storage" + ;; +esac + +if is_not_printable "$f"; then + perview_xxd "$f" else - # `exiftool` did not recognize the file. - hide_script_env xxd -- "$f" + preview_bat "$f" fi diff --git a/modules/by-name/lf/lf/ctpv/prev/application/archive/atool.sh b/modules/by-name/lf/lf/ctpv/prev/application/archive/atool.sh new file mode 100644 index 00000000..5f4baac7 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/application/archive/atool.sh @@ -0,0 +1,11 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" + +. %HELPERS + +atool --list -- "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/application/archive/default.nix b/modules/by-name/lf/lf/ctpv/prev/application/archive/default.nix new file mode 100644 index 00000000..befed06c --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/application/archive/default.nix @@ -0,0 +1,89 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + atool = { + previewer = ./atool.sh; + matches.mime = [ + "application/gzip" + "application/java-archive" + "application/vnd.debian.binary-package" + "application/x-7z-compressed" + "application/x-bzip2" + "application/x-rar" + "application/x-tar" + "application/x-xz" + "application/zip" + "application/zlib" + ]; + + matches.extension = [ + "7z" + "Z" + "a" + "ace" + "alz" + "arc" + "arj" + "bz" + "bz2" + "cab" + "cpio" + "deb" + "gz" + "jar" + "lha" + "lrz" + "lz" + "lzh" + "lzma" + "lzo" + "rar" + "rpm" + "rz" + "t7z" + "tZ" + "tar" + "tar.7z" + "tar.Z" + "tar.bz" + "tar.bz2" + "tar.gz" + "tar.lz" + "tar.lzo" + "tar.xz" + "tbz" + "tbz2" + "tgz" + "tlz" + "txz" + "tzo" + "war" + "xz" + "zip" + ]; + dependencies = [ + pkgs.atool + + # archive tools + pkgs.archiver # for arc + pkgs.arj + pkgs.cpio + pkgs.dpkg + pkgs.file + pkgs.gnutar + pkgs.gzip + pkgs.lzop + pkgs.p7zip + pkgs.pbzip2 + pkgs.plzip + pkgs.rpm + pkgs.unzip + pkgs.xz + pkgs.zip + + # Unfree stuff + # pkgs.lha + # pkgs.rar + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/application/dll/default.nix b/modules/by-name/lf/lf/ctpv/prev/application/dll/default.nix new file mode 100644 index 00000000..00c7e389 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/application/dll/default.nix @@ -0,0 +1,14 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + dll = { + previewer = ./dll.sh; + matches.mime = [ + "application/vnd.microsoft.portable-executable" + ]; + priority = 1; + dependencies = [ + pkgs.tinyxxd + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/application/dll/dll.sh b/modules/by-name/lf/lf/ctpv/prev/application/dll/dll.sh new file mode 100644 index 00000000..678506eb --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/application/dll/dll.sh @@ -0,0 +1,19 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +w="$w" +# shellcheck disable=SC2269 +e="$e" +# shellcheck disable=SC2269 +m="$m" +# shellcheck disable=SC2269 +h="$h" + +. %HELPERS + +preview_xxd "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/application/epub/default.nix b/modules/by-name/lf/lf/ctpv/prev/application/epub/default.nix new file mode 100644 index 00000000..33c51352 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/application/epub/default.nix @@ -0,0 +1,14 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + epub = { + previewer = ./epub.sh; + matches.mime = ["application/epub+zip"]; + matches.extension = ["epub"]; + priority = 1; + dependencies = with pkgs; [ + bk + epub-thumbnailer + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/application/epub/epub.sh b/modules/by-name/lf/lf/ctpv/prev/application/epub/epub.sh new file mode 100644 index 00000000..703e7dad --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/application/epub/epub.sh @@ -0,0 +1,27 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +w="$w" +# shellcheck disable=SC2269 +e="$e" +# shellcheck disable=SC2269 +m="$m" +# shellcheck disable=SC2269 +h="$h" +# shellcheck disable=SC2269 +cache_f="$cache_f" + +. %HELPERS + +epub() { + epub-thumbnailer "$f" "$cache_f" 20000 +} + +convert_and_show_image epub + +bk --meta "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/application/pdf/default.nix b/modules/by-name/lf/lf/ctpv/prev/application/pdf/default.nix new file mode 100644 index 00000000..b27e3ef9 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/application/pdf/default.nix @@ -0,0 +1,12 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + pdf = { + previewer = ./pdf.sh; + matches.mime = ["application/pdf"]; + priority = 1; + dependencies = [ + pkgs.poppler_utils # for `pdftoppm` + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/application/pdf/pdf.sh b/modules/by-name/lf/lf/ctpv/prev/application/pdf/pdf.sh new file mode 100644 index 00000000..2f807b1a --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/application/pdf/pdf.sh @@ -0,0 +1,22 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +cache_f="$cache_f" + +. %HELPERS + +pdf() { + pdftoppm -f 1 -l 1 \ + -scale-to-x 1920 \ + -scale-to-y -1 \ + -singlefile \ + -jpeg \ + -- "$f" "$cache_f" && mv -- "$cache_f.jpg" "$cache_f" +} + +convert_and_show_image pdf diff --git a/modules/by-name/lf/lf/ctpv/prev/application/pgp/default.nix b/modules/by-name/lf/lf/ctpv/prev/application/pgp/default.nix new file mode 100644 index 00000000..c219a1ed --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/application/pgp/default.nix @@ -0,0 +1,17 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + pgp = { + previewer = ./pgp.sh; + matches.extension = ["gpg" "asc" "key" "pgp" "sig"]; + matches.mime = [ + "application/pgp-encrypted" + "application/pgp-keys" + "application/pgp-signature" + ]; + priority = 1; + dependencies = [ + pkgs.sequoia-sq + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/application/pgp/pgp.sh b/modules/by-name/lf/lf/ctpv/prev/application/pgp/pgp.sh new file mode 100644 index 00000000..a4eefd96 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/application/pgp/pgp.sh @@ -0,0 +1,13 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +w="$w" + +. %HELPERS + +hide_script_env sq inspect --certifications -- "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/application/sqlite/default.nix b/modules/by-name/lf/lf/ctpv/prev/application/sqlite/default.nix new file mode 100644 index 00000000..54b8c29e --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/application/sqlite/default.nix @@ -0,0 +1,13 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + sqlite = { + previewer = ./sqlite.sh; + matches.mime = ["application/vnd.sqlite3"]; + priority = 1; + dependencies = [ + pkgs.sqlite + pkgs.bat + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/application/sqlite/sqlite.sh b/modules/by-name/lf/lf/ctpv/prev/application/sqlite/sqlite.sh new file mode 100644 index 00000000..07e77a93 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/application/sqlite/sqlite.sh @@ -0,0 +1,22 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +w="$w" + +. %HELPERS + +echo "SQLite database. Schema:" +echo + +sqlite3 "$f" ".schema --indent" | bat \ + --color always \ + --style plain \ + --paging never \ + --language SQL \ + --terminal-width "$w" \ + --wrap character diff --git a/modules/by-name/lf/lf/ctpv/prev/application/x-bittorrent/default.nix b/modules/by-name/lf/lf/ctpv/prev/application/x-bittorrent/default.nix new file mode 100644 index 00000000..504623a0 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/application/x-bittorrent/default.nix @@ -0,0 +1,11 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + torrent = { + previewer = ./torrent.sh; + matches.mime = ["application/x-bittorrent"]; + dependencies = [ + pkgs.transmission_4 # for `transmission-show` + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/application/x-bittorrent/torrent.sh b/modules/by-name/lf/lf/ctpv/prev/application/x-bittorrent/torrent.sh new file mode 100644 index 00000000..16cfcbcd --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/application/x-bittorrent/torrent.sh @@ -0,0 +1,13 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +cache_f="$cache_f" + +. %HELPERS + +transmission-show -- "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/atool.sh b/modules/by-name/lf/lf/ctpv/prev/atool.sh deleted file mode 100644 index 5f4baac7..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/atool.sh +++ /dev/null @@ -1,11 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" - -. %HELPERS - -atool --list -- "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/audio.sh b/modules/by-name/lf/lf/ctpv/prev/audio.sh deleted file mode 100644 index c5abc646..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/audio.sh +++ /dev/null @@ -1,21 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -cache_f="$cache_f" - -. %HELPERS - -audio() { - ffmpegthumbnailer -i "$f" -s 0 -q 5 -t 10 -o "$cache_f" 2>/dev/null -} - -x="$(ffmpeg -hide_banner -i "$f" 2>&1)" -printf '%s\n' "$x" -y=$((y + $(printf '%s\n' "$x" | wc -l))) - -convert_and_show_image audio diff --git a/modules/by-name/lf/lf/ctpv/prev/audio/audio.sh b/modules/by-name/lf/lf/ctpv/prev/audio/audio.sh new file mode 100644 index 00000000..c5abc646 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/audio/audio.sh @@ -0,0 +1,21 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +cache_f="$cache_f" + +. %HELPERS + +audio() { + ffmpegthumbnailer -i "$f" -s 0 -q 5 -t 10 -o "$cache_f" 2>/dev/null +} + +x="$(ffmpeg -hide_banner -i "$f" 2>&1)" +printf '%s\n' "$x" +y=$((y + $(printf '%s\n' "$x" | wc -l))) + +convert_and_show_image audio diff --git a/modules/by-name/lf/lf/ctpv/prev/audio/default.nix b/modules/by-name/lf/lf/ctpv/prev/audio/default.nix new file mode 100644 index 00000000..97731daf --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/audio/default.nix @@ -0,0 +1,12 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + audio = { + previewer = ./audio.sh; + matches.mime = ["audio/*"]; + dependencies = [ + pkgs.ffmpegthumbnailer + pkgs.ffmpeg + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/bat.sh b/modules/by-name/lf/lf/ctpv/prev/bat.sh deleted file mode 100644 index 760ad50e..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/bat.sh +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -w="$w" - -. %HELPERS - -bat \ - --color always \ - --style plain \ - --paging never \ - --terminal-width "$w" \ - --wrap character \ - -- "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/default.nix b/modules/by-name/lf/lf/ctpv/prev/default.nix new file mode 100644 index 00000000..d8ab36c4 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/default.nix @@ -0,0 +1,23 @@ +{ + pkgs, + config, + ... +}: let + cfg = config.soispha.programs.lf; +in { + soispha.programs.lf.ctpv.previewers = { + any = { + previewer = ./any.sh; + mime_matches = ["*/*"]; + priority = -1; + replacementStrings = { + STORAGE_DIRECTORY = "${cfg.ctpv.xdgDataHome}/ctpv/missing_previews"; + }; + + dependencies = [ + pkgs.tinyxxd # For xxd + pkgs.bat + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/delta.sh b/modules/by-name/lf/lf/ctpv/prev/delta.sh deleted file mode 100644 index 6a4e9a4e..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/delta.sh +++ /dev/null @@ -1,11 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" - -. %HELPERS - -delta <"$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/elinks.sh b/modules/by-name/lf/lf/ctpv/prev/elinks.sh deleted file mode 100644 index ca0de22e..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/elinks.sh +++ /dev/null @@ -1,18 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -w="$w" - -. %HELPERS - -elinks \ - -dump 1 -dump-width "$w" \ - -no-references -no-numbering <"$f" - -# lynx -dump -nonumbers -nolist -width="$w" -- "$f" -# w3m -dump "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/font.sh b/modules/by-name/lf/lf/ctpv/prev/font.sh deleted file mode 100644 index 4065557e..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/font.sh +++ /dev/null @@ -1,18 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -cache_f="$cache_f" - -. %HELPERS - -font() { - fontimage -o "$cache_f.png" "$f" 2>/dev/null && - mv -- "$cache_f.png" "$cache_f" -} - -convert_and_show_image font diff --git a/modules/by-name/lf/lf/ctpv/prev/font/default.nix b/modules/by-name/lf/lf/ctpv/prev/font/default.nix new file mode 100644 index 00000000..f5301008 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/font/default.nix @@ -0,0 +1,17 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + font = { + previewer = ./font.sh; + matches.mime = [ + "font/*" + "application/vnd.ms-opentype" + + # TODO: This should be added (ext: 'eot') <2024-12-04> + # "application/vnd.ms-fontobject" + ]; + dependencies = [ + pkgs.fontforge # for `fontimage` + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/font/font.sh b/modules/by-name/lf/lf/ctpv/prev/font/font.sh new file mode 100644 index 00000000..4065557e --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/font/font.sh @@ -0,0 +1,18 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +cache_f="$cache_f" + +. %HELPERS + +font() { + fontimage -o "$cache_f.png" "$f" 2>/dev/null && + mv -- "$cache_f.png" "$cache_f" +} + +convert_and_show_image font diff --git a/modules/by-name/lf/lf/ctpv/prev/glow.sh b/modules/by-name/lf/lf/ctpv/prev/glow.sh deleted file mode 100644 index 301fe675..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/glow.sh +++ /dev/null @@ -1,17 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -w="$w" - -. %HELPERS - -# 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 deleted file mode 100644 index f162c565..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/gpg.sh +++ /dev/null @@ -1,13 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -w="$w" - -. %HELPERS - -hide_script_env sq inspect -- "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/image.sh b/modules/by-name/lf/lf/ctpv/prev/image.sh deleted file mode 100644 index b5b97668..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/image.sh +++ /dev/null @@ -1,11 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" - -. %HELPERS - -send_image "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/image/default.nix b/modules/by-name/lf/lf/ctpv/prev/image/default.nix new file mode 100644 index 00000000..36700fec --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/image/default.nix @@ -0,0 +1,11 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + image = { + previewer = ./image.sh; + matches.mime = ["image/*"]; + dependencies = [ + # Everything is already in the default dependencies. + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/image/image.sh b/modules/by-name/lf/lf/ctpv/prev/image/image.sh new file mode 100644 index 00000000..b5b97668 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/image/image.sh @@ -0,0 +1,11 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" + +. %HELPERS + +send_image "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/image/svg+xml/default.nix b/modules/by-name/lf/lf/ctpv/prev/image/svg+xml/default.nix new file mode 100644 index 00000000..5b965fd7 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/image/svg+xml/default.nix @@ -0,0 +1,12 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + svg = { + previewer = ./svg.sh; + priority = 1; + matches.mime = ["image/svg+xml"]; + dependencies = [ + pkgs.imagemagick + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/image/svg+xml/svg.sh b/modules/by-name/lf/lf/ctpv/prev/image/svg+xml/svg.sh new file mode 100644 index 00000000..04a06f56 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/image/svg+xml/svg.sh @@ -0,0 +1,17 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +cache_f="$cache_f" + +. %HELPERS + +svg() { + magick "$f" "jpg:$cache_f" +} + +convert_and_show_image svg diff --git a/modules/by-name/lf/lf/ctpv/prev/image/x-xcf/default.nix b/modules/by-name/lf/lf/ctpv/prev/image/x-xcf/default.nix new file mode 100644 index 00000000..a3394ef4 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/image/x-xcf/default.nix @@ -0,0 +1,13 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + xcf = { + previewer = ./xcf.sh; + priority = 1; + matches.mime = ["image/x-xcf"]; + dependencies = [ + # pkgs.gimp + pkgs.exiftool + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/image/x-xcf/xcf.sh b/modules/by-name/lf/lf/ctpv/prev/image/x-xcf/xcf.sh new file mode 100644 index 00000000..1603e337 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/image/x-xcf/xcf.sh @@ -0,0 +1,37 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +cache_f="$cache_f" + +. %HELPERS + +xcf() { + # TODO: Add this (currently it fails, as gimp lacks the `python-fu` evaluator) <2024-11-25> + true + # # source: https://stackoverflow.com/a/20814599 + # # Start gimp with python-fu batch-interpreter + # gimp -i --batch-interpreter=python-fu-eval -b - << EOF + # import gimpfu + # + # def convert(filename): + # img = pdb.gimp_file_load(filename, filename) + # new_name = "$cache_f" + # layer = pdb.gimp_image_merge_visible_layers(img, 1) + # + # pdb.gimp_file_save(img, layer, new_name, new_name) + # pdb.gimp_image_delete(img) + # + # convert('${f}') + # + # pdb.gimp_quit(1) + # EOF +} + +# convert_and_show_image xcf + +exiftool -- "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/inode/default.nix b/modules/by-name/lf/lf/ctpv/prev/inode/default.nix new file mode 100644 index 00000000..1261727e --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/inode/default.nix @@ -0,0 +1,16 @@ +{ ...}: { + soispha.programs.lf.ctpv.previewers = { + ls = { + previewer = ./ls.sh; + priority = 1; + mime_matches = ["inode/directory"]; + dependencies = []; + }; + symlink = { + previewer = ./symlink.sh; + priority = 1; + mime_matches = ["inode/symlink"]; + dependencies = []; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/inode/ls.sh b/modules/by-name/lf/lf/ctpv/prev/inode/ls.sh new file mode 100644 index 00000000..f73bd1c2 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/inode/ls.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +cache_d="$cache_d" +# shellcheck disable=SC2269 +cache_f="$cache_f" + +. %HELPERS + +ls --color --group-directories-first -- "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/inode/symlink.sh b/modules/by-name/lf/lf/ctpv/prev/inode/symlink.sh new file mode 100644 index 00000000..b30957d0 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/inode/symlink.sh @@ -0,0 +1,14 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" + +. %HELPERS + +# +# do nothing because in src/ctpv.c some kind of a "preview" +# is already printed +# diff --git a/modules/by-name/lf/lf/ctpv/prev/jq.sh b/modules/by-name/lf/lf/ctpv/prev/jq.sh deleted file mode 100644 index bf807d1d..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/jq.sh +++ /dev/null @@ -1,11 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" - -. %HELPERS - -jq --color-output . <"$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/ls.sh b/modules/by-name/lf/lf/ctpv/prev/ls.sh deleted file mode 100644 index f73bd1c2..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/ls.sh +++ /dev/null @@ -1,15 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -cache_d="$cache_d" -# shellcheck disable=SC2269 -cache_f="$cache_f" - -. %HELPERS - -ls --color --group-directories-first -- "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/pdf.sh b/modules/by-name/lf/lf/ctpv/prev/pdf.sh deleted file mode 100644 index 2f807b1a..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/pdf.sh +++ /dev/null @@ -1,22 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -cache_f="$cache_f" - -. %HELPERS - -pdf() { - pdftoppm -f 1 -l 1 \ - -scale-to-x 1920 \ - -scale-to-y -1 \ - -singlefile \ - -jpeg \ - -- "$f" "$cache_f" && mv -- "$cache_f.jpg" "$cache_f" -} - -convert_and_show_image pdf diff --git a/modules/by-name/lf/lf/ctpv/prev/remove_default_previews.nix b/modules/by-name/lf/lf/ctpv/prev/remove_default_previews.nix new file mode 100644 index 00000000..1407386b --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/remove_default_previews.nix @@ -0,0 +1,30 @@ +{...}: { + soispha.programs.lf.ctpv.extraConfigPre = '' + remove any + remove atool + remove audio + remove bat + remove cat + remove colordiff + remove delta + remove diff_so_fancy + remove elinks + remove font + remove glow + remove gpg + remove highlight + remove image + remove jq + remove libreoffice + remove ls + remove lynx + remove mdcat + remove pdf + remove source_highlight + remove svg + remove symlink + remove torrent + remove video + remove w3m + ''; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/svg.sh b/modules/by-name/lf/lf/ctpv/prev/svg.sh deleted file mode 100644 index 0c82025f..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/svg.sh +++ /dev/null @@ -1,17 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -cache_f="$cache_f" - -. %HELPERS - -svg() { - magick convert "$f" "jpg:$cache_f" -} - -convert_and_show_image svg diff --git a/modules/by-name/lf/lf/ctpv/prev/symlink.sh b/modules/by-name/lf/lf/ctpv/prev/symlink.sh deleted file mode 100644 index b30957d0..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/symlink.sh +++ /dev/null @@ -1,14 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" - -. %HELPERS - -# -# do nothing because in src/ctpv.c some kind of a "preview" -# is already printed -# diff --git a/modules/by-name/lf/lf/ctpv/prev/text/bat.sh b/modules/by-name/lf/lf/ctpv/prev/text/bat.sh new file mode 100644 index 00000000..be952aea --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/text/bat.sh @@ -0,0 +1,13 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +w="$w" + +. %HELPERS + +preview_bat "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/text/default.nix b/modules/by-name/lf/lf/ctpv/prev/text/default.nix new file mode 100644 index 00000000..14e74a4d --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/text/default.nix @@ -0,0 +1,21 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + glow = { + previewer = ./glow.sh; + priority = 1; + matches.extension = ["md"]; + dependencies = [ + pkgs.glow + ]; + }; + + bat = { + priority = 0; + previewer = ./bat.sh; + matches.mime = ["text/*"]; + dependencies = [ + pkgs.bat + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/text/diff/default.nix b/modules/by-name/lf/lf/ctpv/prev/text/diff/default.nix new file mode 100644 index 00000000..e0fa15bb --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/text/diff/default.nix @@ -0,0 +1,12 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + delta = { + previewer = ./delta.sh; + priority = 1; + matches.mime = ["text/x-diff" "text/x-patch"]; + dependencies = [ + pkgs.delta + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/text/diff/delta.sh b/modules/by-name/lf/lf/ctpv/prev/text/diff/delta.sh new file mode 100644 index 00000000..6a4e9a4e --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/text/diff/delta.sh @@ -0,0 +1,11 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" + +. %HELPERS + +delta <"$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/text/glow.sh b/modules/by-name/lf/lf/ctpv/prev/text/glow.sh new file mode 100644 index 00000000..301fe675 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/text/glow.sh @@ -0,0 +1,17 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +w="$w" + +. %HELPERS + +# 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/text/html/default.nix b/modules/by-name/lf/lf/ctpv/prev/text/html/default.nix new file mode 100644 index 00000000..2a7a9a9f --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/text/html/default.nix @@ -0,0 +1,13 @@ +{pkgs, ...}: { + # TODO: I might want to use lynx/w3m instead <2024-11-24> + soispha.programs.lf.ctpv.previewers = { + elinks = { + previewer = ./elinks.sh; + priority = 1; + matches.mime = ["text/html"]; + dependencies = [ + pkgs.elinks + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/text/html/elinks.sh b/modules/by-name/lf/lf/ctpv/prev/text/html/elinks.sh new file mode 100644 index 00000000..ca0de22e --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/text/html/elinks.sh @@ -0,0 +1,18 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +w="$w" + +. %HELPERS + +elinks \ + -dump 1 -dump-width "$w" \ + -no-references -no-numbering <"$f" + +# lynx -dump -nonumbers -nolist -width="$w" -- "$f" +# w3m -dump "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/text/json/default.nix b/modules/by-name/lf/lf/ctpv/prev/text/json/default.nix new file mode 100644 index 00000000..7e2ef090 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/text/json/default.nix @@ -0,0 +1,12 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + jq = { + previewer = ./jq.sh; + priority = 1; + matches.mime = ["application/json"]; + dependencies = [ + pkgs.jq + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/text/json/jq.sh b/modules/by-name/lf/lf/ctpv/prev/text/json/jq.sh new file mode 100644 index 00000000..bf807d1d --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/text/json/jq.sh @@ -0,0 +1,11 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" + +. %HELPERS + +jq --color-output . <"$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/torrent.sh b/modules/by-name/lf/lf/ctpv/prev/torrent.sh deleted file mode 100644 index 16cfcbcd..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/torrent.sh +++ /dev/null @@ -1,13 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -cache_f="$cache_f" - -. %HELPERS - -transmission-show -- "$f" diff --git a/modules/by-name/lf/lf/ctpv/prev/video.sh b/modules/by-name/lf/lf/ctpv/prev/video.sh deleted file mode 100644 index e42e3612..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/video.sh +++ /dev/null @@ -1,17 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -cache_f="$cache_f" - -. %HELPERS - -video() { - ffmpegthumbnailer -i "$f" -o "$cache_f" -s 0 -t 50% 2>/dev/null -} - -convert_and_show_image video diff --git a/modules/by-name/lf/lf/ctpv/prev/video/default.nix b/modules/by-name/lf/lf/ctpv/prev/video/default.nix new file mode 100644 index 00000000..47749d2c --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/video/default.nix @@ -0,0 +1,11 @@ +{pkgs, ...}: { + soispha.programs.lf.ctpv.previewers = { + video = { + previewer = ./video.sh; + matches.mime = ["video/*"]; + dependencies = [ + pkgs.ffmpegthumbnailer + ]; + }; + }; +} diff --git a/modules/by-name/lf/lf/ctpv/prev/video/video.sh b/modules/by-name/lf/lf/ctpv/prev/video/video.sh new file mode 100644 index 00000000..e42e3612 --- /dev/null +++ b/modules/by-name/lf/lf/ctpv/prev/video/video.sh @@ -0,0 +1,17 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH + +# shellcheck disable=SC2269 +f="$f" +# shellcheck disable=SC2269 +cache_f="$cache_f" + +. %HELPERS + +video() { + ffmpegthumbnailer -i "$f" -o "$cache_f" -s 0 -t 50% 2>/dev/null +} + +convert_and_show_image video diff --git a/modules/by-name/lf/lf/ctpv/prev/xcf.sh b/modules/by-name/lf/lf/ctpv/prev/xcf.sh deleted file mode 100644 index 1603e337..00000000 --- a/modules/by-name/lf/lf/ctpv/prev/xcf.sh +++ /dev/null @@ -1,37 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.2" . %SHELL_LIBRARY_PATH - -# shellcheck disable=SC2269 -f="$f" -# shellcheck disable=SC2269 -cache_f="$cache_f" - -. %HELPERS - -xcf() { - # TODO: Add this (currently it fails, as gimp lacks the `python-fu` evaluator) <2024-11-25> - true - # # source: https://stackoverflow.com/a/20814599 - # # Start gimp with python-fu batch-interpreter - # gimp -i --batch-interpreter=python-fu-eval -b - << EOF - # import gimpfu - # - # def convert(filename): - # img = pdb.gimp_file_load(filename, filename) - # new_name = "$cache_f" - # layer = pdb.gimp_image_merge_visible_layers(img, 1) - # - # pdb.gimp_file_save(img, layer, new_name, new_name) - # pdb.gimp_image_delete(img) - # - # convert('${f}') - # - # pdb.gimp_quit(1) - # EOF -} - -# convert_and_show_image xcf - -exiftool -- "$f" diff --git a/modules/by-name/lf/lf/module.nix b/modules/by-name/lf/lf/module.nix index 840ba492..bff2feb0 100644 --- a/modules/by-name/lf/lf/module.nix +++ b/modules/by-name/lf/lf/module.nix @@ -12,6 +12,10 @@ cfg = config.soispha.programs.lf; in { + imports = [ + ./ctpv + ]; + options.soispha.programs.lf = { enable = lib.mkEnableOption "lf"; keymaps = { @@ -43,7 +47,6 @@ in { xdg.configFile = { "lf/icons".source = ./icons; "lf/colors".source = ./colors; - "ctpv/config".text = import ./ctpv {inherit pkgs sysLib lib;}; }; programs.lf = { -- cgit 1.4.1