@@ -76,6 +76,8 @@ IMAGE_CACHE_PATH="$(dirname "$1")"/.thumbs
FPATH="$1"
FNAME=$(basename "$1")
EDITOR="${EDITOR:-vi}"
PAGER="${PAGER:-less -R}"
ext="${FNAME##*.}"
if ! [ -z "$ext" ]; then
ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
@@ -87,13 +89,13 @@ handle_pdf() {
exit 0
elif which pdftotext >/dev/null 2>&1; then
## Preview as text conversion
pdftotext -l 10 -nopgbrk -q -- "${FPATH}" - | less -R
pdftotext -l 10 -nopgbrk -q -- "${FPATH}" - | eval "$PAGER"
exit 0
elif which mutool >/dev/null 2>&1; then
mutool draw -F txt -i -- "${FPATH}" 1-10
exit 0
elif which exiftool >/dev/null 2>&1; then
exiftool "${FPATH}" | less -R
exiftool "${FPATH}" | eval "$PAGER"
exit 0
fi
}
@@ -106,10 +108,10 @@ handle_audio() {
mpv "${FPATH}" >/dev/null 2>&1 &
exit 0
elif which mediainfo >/dev/null 2>&1; then
mediainfo "${FPATH}" | less -R
mediainfo "${FPATH}" | eval "$PAGER"
exit 0
elif which exiftool >/dev/null 2>&1; then
exiftool "${FPATH}"| less -R
exiftool "${FPATH}"| eval "$PAGER"
exit 0
fi
}
@@ -125,13 +127,13 @@ handle_video() {
# Thumbnail
[ -d "${IMAGE_CACHE_PATH}" ] || mkdir "${IMAGE_CACHE_PATH}"
ffmpegthumbnailer -i "${FPATH}" -o "${IMAGE_CACHE_PATH}/${FNAME}.jpg" -s 0
viu -n "${IMAGE_CACHE_PATH}/${FNAME}.jpg" | less -R
viu -n "${IMAGE_CACHE_PATH}/${FNAME}.jpg" | eval "$PAGER"
exit 0
elif which mediainfo >/dev/null 2>&1; then
mediainfo "${FPATH}" | less -R
mediainfo "${FPATH}" | eval "$PAGER"
exit 0
elif which exiftool >/dev/null 2>&1; then
exiftool "${FPATH}"| less -R
exiftool "${FPATH}"| eval "$PAGER"
exit 0
fi
}
@@ -143,23 +145,23 @@ handle_extension() {
a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
if which atool >/dev/null 2>&1; then
atool --list -- "${FPATH}" | less -R
atool --list -- "${FPATH}" | eval "$PAGER"
exit 0
elif which bsdtar >/dev/null 2>&1; then
bsdtar --list --file "${FPATH}" | less -R
bsdtar --list --file "${FPATH}" | eval "$PAGER"
exit 0
fi
exit 1;;
rar)
if which unrar >/dev/null 2>&1; then
## Avoid password prompt by providing empty password
unrar lt -p- -- "${FPATH}" | less -R
unrar lt -p- -- "${FPATH}" | eval "$PAGER"
fi
exit 1;;
7z)
if which 7z >/dev/null 2>&1; then
## Avoid password prompt by providing empty password
7z l -p -- "${FPATH}" | less -R
7z l -p -- "${FPATH}" | eval "$PAGER"
exit 0
fi
exit 1;;
@@ -181,7 +183,7 @@ handle_extension() {
## Log files
log)
vi "${FPATH}"
"$EDITOR" "${FPATH}"
exit 0;;
## BitTorrent
@@ -199,7 +201,7 @@ handle_extension() {
odt|ods|odp|sxw)
if which odt2txt >/dev/null 2>&1; then
## Preview as text conversion
odt2txt "${FPATH}" | less -R
odt2txt "${FPATH}" | eval "$PAGER"
exit 0
fi
exit 1;;
@@ -207,10 +209,10 @@ handle_extension() {
## Markdown
md)
if which glow >/dev/null 2>&1; then
glow -sdark "${FPATH}" | less -R
glow -sdark "${FPATH}" | eval "$PAGER"
exit 0
elif which lowdown >/dev/null 2>&1; then
lowdown -Tterm "${FPATH}" | less -R
lowdown -Tterm "${FPATH}" | eval "$PAGER"
exit 0
fi
;;
@@ -219,13 +221,13 @@ handle_extension() {
htm|html|xhtml)
## Preview as text conversion
if which w3m >/dev/null 2>&1; then
w3m -dump "${FPATH}" | less -R
w3m -dump "${FPATH}" | eval "$PAGER"
exit 0
elif which lynx >/dev/null 2>&1; then
lynx -dump -- "${FPATH}" | less -R
lynx -dump -- "${FPATH}" | eval "$PAGER"
exit 0
elif which elinks >/dev/null 2>&1; then
elinks -dump "${FPATH}" | less -R
elinks -dump "${FPATH}" | eval "$PAGER"
exit 0
fi
;;
@@ -233,10 +235,10 @@ handle_extension() {
## JSON
json)
if which jq >/dev/null 2>&1; then
jq --color-output . "${FPATH}" | less -R
jq --color-output . "${FPATH}" | eval "$PAGER"
exit 0
elif which python >/dev/null 2>&1; then
python -m json.tool -- "${FPATH}" | less -R
python -m json.tool -- "${FPATH}" | eval "$PAGER"
exit 0
fi
;;
@@ -292,13 +294,13 @@ handle_multimedia() {
sxiv_load_dir "${FPATH}" >/dev/null 2>&1 &
exit 0
elif which viu >/dev/null 2>&1; then
viu -n "${FPATH}" | less -R
viu -n "${FPATH}" | eval "$PAGER"
exit 0
elif which img2txt >/dev/null 2>&1; then
img2txt --gamma=0.6 -- "${FPATH}" | less -R
img2txt --gamma=0.6 -- "${FPATH}" | eval "$PAGER"
exit 0
elif which exiftool >/dev/null 2>&1; then
exiftool "${FPATH}" | less -R
exiftool "${FPATH}" | eval "$PAGER"
exit 0
fi
# local orientation
@@ -418,7 +420,7 @@ handle_mime() {
## Text
text/* | */xml)
vi "${FPATH}"
"$EDITOR" "${FPATH}"
exit 0;;
## Syntax highlight
# if [[ "$( stat --printf='%s' -- "${FPATH}" )" -gt "${HIGHLIGHT_SIZE_MAX}" ]]; then
@@ -442,10 +444,10 @@ handle_mime() {
image/vnd.djvu)
if which djvutxt >/dev/null 2>&1; then
## Preview as text conversion (requires djvulibre)
djvutxt "${FPATH}" | less -R
djvutxt "${FPATH}" | eval "$PAGER"
exit 0
elif which exiftool >/dev/null 2>&1; then
exiftool "${FPATH}" | less -R
exiftool "${FPATH}" | eval "$PAGER"
exit 0
fi
exit 1;;