From 4c25bedde25d9f17498299007d2dabafc92c3770 Mon Sep 17 00:00:00 2001 From: Emmet Date: Sat, 13 Apr 2024 12:38:18 -0500 Subject: [PATCH] Added a lot more ranger file previews! --- user/app/ranger/rc.conf | 2 +- user/app/ranger/scope.sh | 93 +++++++++++++++++++++++----------------- user/pkgs/ranger.nix | 7 ++- 3 files changed, 60 insertions(+), 42 deletions(-) diff --git a/user/app/ranger/rc.conf b/user/app/ranger/rc.conf index c196c0d..6a8cdfa 100644 --- a/user/app/ranger/rc.conf +++ b/user/app/ranger/rc.conf @@ -256,7 +256,7 @@ set cd_tab_fuzzy false # Avoid previewing files larger than this size, in bytes. Use a value of 0 to # disable this feature. -set preview_max_size 200000000 +set preview_max_size 0 # The key hint lists up to this size have their sublists expanded. # Otherwise the submaps are replaced with "...". diff --git a/user/app/ranger/scope.sh b/user/app/ranger/scope.sh index d58637e..005469d 100755 --- a/user/app/ranger/scope.sh +++ b/user/app/ranger/scope.sh @@ -170,29 +170,29 @@ handle_image() { ## as above), but might fail for unsupported types. exit 7;; - ## Video - # video/*) - # # Get embedded thumbnail - # ffmpeg -i "${FILE_PATH}" -map 0:v -map -0:V -c copy "${IMAGE_CACHE_PATH}" && exit 6 - # # Get frame 10% into video - # ffmpegthumbnailer -i "${FILE_PATH}" -o "${IMAGE_CACHE_PATH}" -s 0 && exit 6 - # exit 1;; + # Video + video/*) + # Get frame 10% into video + ffmpegthumbnailer -i "${FILE_PATH}" -o "${IMAGE_CACHE_PATH}" -s 0 && exit 6 + # Get embedded thumbnail + ffmpeg -i "${FILE_PATH}" -map 0:v -map -0:V -c copy "${IMAGE_CACHE_PATH}" && exit 6 + exit 1;; - ## Audio - # audio/*) - # # Get embedded thumbnail - # ffmpeg -i "${FILE_PATH}" -map 0:v -map -0:V -c copy \ - # "${IMAGE_CACHE_PATH}" && exit 6;; + # Audio + audio/*) + # Get embedded thumbnail + ffmpeg -i "${FILE_PATH}" -map 0:v -map -0:V -c copy \ + "${IMAGE_CACHE_PATH}" && exit 6;; - ## PDF - # application/pdf) - # pdftoppm -f 1 -l 1 \ - # -scale-to-x "${DEFAULT_SIZE%x*}" \ - # -scale-to-y -1 \ - # -singlefile \ - # -jpeg -tiffcompression jpeg \ - # -- "${FILE_PATH}" "${IMAGE_CACHE_PATH%.*}" \ - # && exit 6 || exit 1;; + # PDF + application/pdf) + pdftoppm -f 1 -l 1 \ + -scale-to-x "${DEFAULT_SIZE%x*}" \ + -scale-to-y -1 \ + -singlefile \ + -jpeg -tiffcompression jpeg \ + -- "${FILE_PATH}" "${IMAGE_CACHE_PATH%.*}" \ + && exit 6 || exit 1;; ## ePub, MOBI, FB2 (using Calibre) @@ -205,7 +205,7 @@ handle_image() { # >/dev/null && exit 6 # exit 1;; - ## Font + # Font application/font*|application/*opentype) preview_png="/tmp/$(basename "${IMAGE_CACHE_PATH%.*}").png" if fontimage -o "${preview_png}" \ @@ -265,29 +265,42 @@ handle_image() { # ;; esac - # openscad_image() { - # TMPPNG="$(mktemp -t xxxxxx.png)" - # openscad --colorscheme="${OPENSCAD_COLORSCHEME}" \ - # --imgsize="${OPENSCAD_IMGSIZE/x/,}" \ - # -o "${TMPPNG}" "${1}" - # mv "${TMPPNG}" "${IMAGE_CACHE_PATH}" - # } + openscad_image() { + TMPPNG="$(mktemp -t XXXXXXXXXX --suffix '.png')" + openscad --colorscheme="${OPENSCAD_COLORSCHEME}" \ + --imgsize="${OPENSCAD_IMGSIZE/x/,}" \ + -o "${TMPPNG}" "${1}" + mv "${TMPPNG}" "${IMAGE_CACHE_PATH}" + } + FULL_FILE_PATH=$(readlink -f $FILE_PATH); case "${FILE_EXTENSION_LOWER}" in - ## 3D models - ## OpenSCAD only supports png image output, and ${IMAGE_CACHE_PATH} - ## is hardcoded as jpeg. So we make a tempfile.png and just - ## move/rename it to jpg. This works because image libraries are - ## smart enough to handle it. - # csg|scad) - # openscad_image "${FILE_PATH}" && exit 6 - # ;; - # 3mf|amf|dxf|off|stl) - # openscad_image <(echo "import(\"${FILE_PATH}\");") && exit 6 - # ;; + # 3D models + # OpenSCAD only supports png image output, and ${IMAGE_CACHE_PATH} + # is hardcoded as jpeg. So we make a tempfile.png and just + # move/rename it to jpg. This works because image libraries are + # smart enough to handle it. + csg|scad) + openscad_image "${FILE_PATH}" && exit 6 + ;; + stl) + openscad_image <(echo "import(\"${FULL_FILE_PATH}\");") && exit 6 + ;; + 3mf|amf|dxf|off|stl) + openscad_image <(echo "import(\"${FULL_FILE_PATH}\");") && exit 6 + ;; drawio) draw.io -x "${FILE_PATH}" -o "${IMAGE_CACHE_PATH}" \ --width "${DEFAULT_SIZE%x*}" && exit 6 + ;; + blend|blend~) + blender-thumbnailer "${FILE_PATH}" "${IMAGE_CACHE_PATH}" && exit 6 + ;; + kra|kra~) + unzip -pP "" -- "${FILE_PATH}" "mergedimage.png" > "${IMAGE_CACHE_PATH}" && exit 6 + ;; + xopp|xopp~) + xournalpp "${FILE_PATH}" --create-img "${IMAGE_CACHE_PATH}" && exit 6 exit 1;; esac } diff --git a/user/pkgs/ranger.nix b/user/pkgs/ranger.nix index 5f579c7..4a56abb 100644 --- a/user/pkgs/ranger.nix +++ b/user/pkgs/ranger.nix @@ -7,7 +7,7 @@ ranger = super.ranger.overrideAttrs (oldAttrs: rec { preConfigure = '' substituteInPlace ranger/__init__.py \ - --replace "DEFAULT_PAGER = 'less'" "DEFAULT_PAGER = '${lib.getBin pkgs.less}/bin/less'" + --replace "DEFAULT_PAGER = 'less'" "DEFAULT_PAGER = '${lib.getBin pkgs.bat}/bin/bat'" # give image previews out of the box when building with w3m substituteInPlace ranger/config/rc.conf \ @@ -28,5 +28,10 @@ } ) ]; + home.packages = with pkgs; [ + poppler_utils + librsvg + ffmpegthumbnailer + ]; }