scope-lol
This commit is contained in:
parent
42987c2d64
commit
a2d716606e
1 changed files with 30 additions and 37 deletions
|
@ -1,51 +1,44 @@
|
|||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
|
||||
# File preview handler for lf.
|
||||
|
||||
set -C -f
|
||||
#IFS=$'\n'
|
||||
IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}"
|
||||
|
||||
# ANSI color codes are supported.
|
||||
# STDIN is disabled, so interactive scripts won't work properly
|
||||
|
||||
# This script is considered a configuration file and must be updated manually.
|
||||
|
||||
# Meanings of exit codes:
|
||||
# code | meaning | action of ranger
|
||||
# -----+------------+-------------------------------------------
|
||||
# 0 | success | Display stdout as preview
|
||||
# 1 | no preview | Display no preview at all
|
||||
# 2 | plain text | Display the plain content of the file
|
||||
|
||||
# Script arguments
|
||||
FILE_PATH="${1}" # Full path of the highlighted file
|
||||
|
||||
#FILE_EXTENSION="${FILE_PATH##*.}"
|
||||
#FILE_EXTENSION_LOWER=$(echo ${FILE_EXTENSION} | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
# Settings
|
||||
export HIGHLIGHT_SIZE_MAX=262143 # 256KiB
|
||||
export HIGHLIGHT_TABWIDTH=8
|
||||
export HIGHLIGHT_STYLE='pablo'
|
||||
|
||||
image() {
|
||||
if [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ] && command -V ueberzug >/dev/null 2>&1; then
|
||||
printf '{"action": "add", "identifier": "PREVIEW", "x": "%s", "y": "%s", "width": "%s", "height": "%s", "scaler": "contain", "path": "%s"}\n' "$4" "$5" "$(($2-1))" "$(($3-1))" "$1" > "$FIFO_UEBERZUG"
|
||||
exit 1
|
||||
else
|
||||
mediainfo "$1"
|
||||
fi
|
||||
}
|
||||
CACHE="$HOME/.cache/lf/thumbnail.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}'))"
|
||||
|
||||
case "$(file --dereference --brief --mime-type -- "${FILE_PATH}")" in
|
||||
image/*) image "$FILE_PATH" "$2" "$3" "$4" "$5" ;;
|
||||
text/html) lynx -display_charset=utf-8 -dump "${FILE_PATH}" ;;
|
||||
text/troff) man ./ "${FILE_PATH}" | col -b ;;
|
||||
text/* | */xml) bat -f "${FILE_PATH}" ;;
|
||||
application/zip) atool --list -- "${FILE_PATH}" ;;
|
||||
video/* | audio/* | application/octet-stream) mediainfo "${FILE_PATH}" || exit 1;;
|
||||
*/pdf) pdftotext -l 10 -nopgbrk -q -- "${FILE_PATH}" - ;;
|
||||
*opendocument*) odt2txt "${FILE_PATH}" ;;
|
||||
application/pgp-encrypted) gpg -d -- "${FILE_PATH}" ;;
|
||||
ifub() {
|
||||
[ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ] && command -V ueberzug >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Note that the cache file name is a function of file information, meaning if
|
||||
# an image appears in multiple places across the machine, it will not have to
|
||||
# be regenerated once seen.
|
||||
|
||||
case "$(file --dereference --brief --mime-type -- "$1")" in
|
||||
image/*) image "$1" "$2" "$3" "$4" "$5" ;;
|
||||
text/html) lynx -width="$4" -display_charset=utf-8 -dump "$1" ;;
|
||||
text/troff) man ./ "$1" | col -b ;;
|
||||
text/* | */xml) bat --terminal-width "$4" -f "$1" ;;
|
||||
application/zip) atool --list -- "$1" ;;
|
||||
audio/* | application/octet-stream) mediainfo "$1" || exit 1;;
|
||||
video/* )
|
||||
CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')"
|
||||
[ ! -f "$CACHE" ] && ffmpegthumbnailer -i "$1" -o "$CACHE" -s 0
|
||||
image "$CACHE" "$2" "$3" "$4" "$5"
|
||||
;;
|
||||
*/pdf)
|
||||
CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/lf/thumb.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | sha256sum | awk '{print $1}')"
|
||||
[ ! -f "$CACHE.jpg" ] && pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE"
|
||||
image "$CACHE.jpg" "$2" "$3" "$4" "$5"
|
||||
;;
|
||||
*opendocument*) odt2txt "$1" ;;
|
||||
application/pgp-encrypted) gpg -d -- "$1" ;;
|
||||
esac
|
||||
exit 1
|
||||
|
|
Loading…
Reference in a new issue