voidrice/.config/lf/scope

52 lines
1.9 KiB
Text
Raw Normal View History

2019-09-23 10:10:28 +00:00
#!/bin/bash
2019-05-24 02:59:30 +00:00
2022-03-06 18:27:22 +00:00
set -C -f
2019-05-24 02:59:30 +00:00
#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
2019-09-23 10:10:28 +00:00
#FILE_EXTENSION="${FILE_PATH##*.}"
#FILE_EXTENSION_LOWER=$(echo ${FILE_EXTENSION} | tr '[:upper:]' '[:lower:]')
2019-05-24 02:59:30 +00:00
# Settings
2022-03-06 18:27:22 +00:00
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}'))"
2019-05-24 02:59:30 +00:00
2022-03-06 18:27:22 +00:00
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}" ;;
2019-09-23 10:10:28 +00:00
text/troff) man ./ "${FILE_PATH}" | col -b ;;
2022-03-06 18:27:22 +00:00
text/* | */xml) bat -f "${FILE_PATH}" ;;
2019-09-23 10:10:28 +00:00
application/zip) atool --list -- "${FILE_PATH}" ;;
2022-03-06 18:27:22 +00:00
video/* | audio/* | application/octet-stream) mediainfo "${FILE_PATH}" || exit 1;;
2019-09-23 10:10:28 +00:00
*/pdf) pdftotext -l 10 -nopgbrk -q -- "${FILE_PATH}" - ;;
*opendocument*) odt2txt "${FILE_PATH}" ;;
2022-03-06 18:27:22 +00:00
application/pgp-encrypted) gpg -d -- "${FILE_PATH}" ;;
esac
2019-05-24 02:59:30 +00:00
exit 1