51 lines
1.9 KiB
Bash
Executable file
51 lines
1.9 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
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}" ;;
|
|
esac
|
|
exit 1
|