diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | doc/ranger.pod | 11 | ||||
-rwxr-xr-x | ranger/data/scope.sh | 24 |
3 files changed, 36 insertions, 0 deletions
diff --git a/README.md b/README.md index bf1533a6..8134bc59 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ For enhanced file previews (with `scope.sh`): * `odt2txt` for OpenDocument text files (`odt`, `ods`, `odp` and `sxw`) * `python` or `jq` for JSON files * `fontimage` for font previews +* `openscad` for 3D model previews (`stl`, `off`, `dxf`, `scad`, `csg`) Installing ---------- diff --git a/doc/ranger.pod b/doc/ranger.pod index 911b6480..33b16b92 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -1974,6 +1974,17 @@ I<highlight> will pick up command line options specified in this variable. A C<--style=> option specified here will override C<HIGHLIGHT_STYLE>. Similarly, C<--replace-tabs=> will override C<HIGHLIGHT_TABWIDTH>. +=item OPENSCAD_COLORSCHEME + +Specifies the colorscheme used by I<openscad> while previewing 3D models. Read +I<openscad> man page for colorschemes. Ranger will default to Tomorrow Night. + +=item OPENSCAD_IMGSIZE + +Specifies the internal resolution I<openscad> will use for rendering 3D models. +The image will be downscaled to fit the preview pane. This resolution will +default to "1000,1000" if no value is set. + =item XDG_CONFIG_HOME Specifies the directory for configuration files. Defaults to F<$HOME/.config>. diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index caa9475f..f2b9ff9c 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -44,6 +44,8 @@ HIGHLIGHT_TABWIDTH=${HIGHLIGHT_TABWIDTH:-8} HIGHLIGHT_STYLE=${HIGHLIGHT_STYLE:-pablo} HIGHLIGHT_OPTIONS="--replace-tabs=${HIGHLIGHT_TABWIDTH} --style=${HIGHLIGHT_STYLE} ${HIGHLIGHT_OPTIONS:-}" PYGMENTIZE_STYLE=${PYGMENTIZE_STYLE:-autumn} +OPENSCAD_IMGSIZE=${RNGR_OPENSCAD_IMGSIZE:-1000,1000} +OPENSCAD_COLORSCHEME=${RNGR_OPENSCAD_COLORSCHEME:-Tomorrow Night} handle_extension() { case "${FILE_EXTENSION_LOWER}" in @@ -95,6 +97,28 @@ handle_extension() { python -m json.tool -- "${FILE_PATH}" && exit 5 ;; + ## 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 library is smart enough to handle it + stl|off|dxf) + [[ "${PV_IMAGE_ENABLED}" != 'True' ]] && exit 1 + openscad --colorscheme="${OPENSCAD_COLORSCHEME}" \ + --imgsize="${OPENSCAD_IMGSIZE/x/,}" \ + -o "/tmp/$(basename "${FILE_PATH}").png" \ + <(echo "import(\"${FILE_PATH}\");") + mv "/tmp/$(basename "${FILE_PATH}").png" "${IMAGE_CACHE_PATH}" \ + && exit 6 + ;; + scad|csg) + [[ "${PV_IMAGE_ENABLED}" != 'True' ]] && exit 1 + openscad --colorscheme="${OPENSCAD_COLORSCHEME}" \ + --imgsize="${OPENSCAD_IMGSIZE/x/,}" \ + -o "/tmp/$(basename "${FILE_PATH}").png" "${FILE_PATH}" + mv "/tmp/$(basename "${FILE_PATH}").png" "${IMAGE_CACHE_PATH}" \ + && exit 6 + ;; + ## Direct Stream Digital/Transfer (DSDIFF) dsf) mediainfo "${FILE_PATH}" && exit 5 |