previewer overhaul
This commit is contained in:
parent
f8a6b5d935
commit
67b52b5b66
|
@ -6,15 +6,26 @@ set scrolloff 10
|
||||||
set icons
|
set icons
|
||||||
set wrapscroll
|
set wrapscroll
|
||||||
set period 1
|
set period 1
|
||||||
set findlen 2
|
|
||||||
set previewer ~/.config/lf/preview
|
set previewer ~/.config/lf/preview
|
||||||
set cleaner ~/.config/lf/clean
|
set cleaner ~/.config/lf/clean
|
||||||
set promptfmt "\033[34;1m%u\033[36m@\033[34m%h \033[35m[\033[0;1m%d\033[33m%f\033[35m]\033[0m"
|
set promptfmt "\033[34;1m%u\033[36m@\033[34m%h \033[35m[\033[0;1m%d\033[33m%f\033[35m]\033[0m"
|
||||||
|
|
||||||
cmd open ${{
|
cmd open ${{
|
||||||
case $(file --mime-type "$(readlink -f $f)" -b) in
|
case $(xdg-mime query filetype "$1") in
|
||||||
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet) localc $fx ;;
|
*/x-bzip-compressed-tar|*/x-compressed-tar|*/x-7z-compressed|*/vnd.rar|*/x-tar|*/zip|*/x-java-archive|*/x-xz|*/x-cd-image)
|
||||||
image/vnd.djvu|application/pdf|application/octet-stream|application/postscript) setsid -f zathura $fx >/dev/null 2>&1 ;;
|
mntdir="$f-archivemount"
|
||||||
|
[ ! -d "$mntdir" ] && {
|
||||||
|
mkdir "$mntdir"
|
||||||
|
archivemount "$f" "$mntdir"
|
||||||
|
echo "$mntdir" >> "/tmp/__lf_archivemount_$id"
|
||||||
|
}
|
||||||
|
lf -remote "send $id cd \"$mntdir\""
|
||||||
|
lf -remote "send $id reload"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
case $(file -bL --mime-type) in
|
||||||
|
*/vnd.openxmlformats-officedocument*) localc $fx ;;
|
||||||
|
*/pdf|application/vnd*|application/epub*) setsid -f zathura $fx >/dev/null 2>&1 ;;
|
||||||
text/*|application/json|inode/x-empty) $EDITOR $fx;;
|
text/*|application/json|inode/x-empty) $EDITOR $fx;;
|
||||||
image/x-xcf) setsid -f gimp $f >/dev/null 2>&1 ;;
|
image/x-xcf) setsid -f gimp $f >/dev/null 2>&1 ;;
|
||||||
image/svg+xml) display -- $f ;;
|
image/svg+xml) display -- $f ;;
|
||||||
|
@ -27,7 +38,6 @@ cmd open ${{
|
||||||
;;
|
;;
|
||||||
audio/*) mpv --audio-display=no $f ;;
|
audio/*) mpv --audio-display=no $f ;;
|
||||||
video/*) setsid -f mpv $f -quiet >/dev/null 2>&1 ;;
|
video/*) setsid -f mpv $f -quiet >/dev/null 2>&1 ;;
|
||||||
application/pdf|application/vnd*|application/epub*) setsid -f zathura $fx >/dev/null 2>&1 ;;
|
|
||||||
application/pgp-encrypted) $EDITOR $fx ;;
|
application/pgp-encrypted) $EDITOR $fx ;;
|
||||||
*) for f in $fx; do setsid -f $OPENER $f >/dev/null 2>&1; done;;
|
*) for f in $fx; do setsid -f $OPENER $f >/dev/null 2>&1; done;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -1,72 +1,65 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
image() {
|
image() {
|
||||||
file=$1
|
f=$1
|
||||||
w=$2
|
w=$2
|
||||||
h=$3
|
h=$3
|
||||||
x=$4
|
x=$4
|
||||||
y=$5
|
y=$5
|
||||||
if [ -n "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
|
kitty +icat --silent --transfer-mode file --place "${w}x${h}@${x}x${y}" "$f" && return 0
|
||||||
kitty +icat --silent --transfer-mode file --place "${w}x${h}@${x}x${y}" "$file"
|
chafa "$f" -f symbols -s "$(($w-2))x$h" && return 0
|
||||||
else
|
echo -e "\e[31mImage previewer not installed\e[0m"
|
||||||
chafa "$1" -s "$4x"
|
return 1
|
||||||
fi
|
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
video() {
|
video() {
|
||||||
thumb="$(vidthumb "$file")"
|
f=$1
|
||||||
if [ "$thumb" != "" ]; then
|
w=$2
|
||||||
image "$1" "$2" "$3" "$4" "$5"
|
h=$3
|
||||||
exit 1
|
x=$4
|
||||||
fi
|
y=$5
|
||||||
mediainfo "$file"
|
command -v vidthumb && thumb="$(vidthumb "$f")" || echo -e "\e[31mvidthumb script not in path\e[0m" && return 1
|
||||||
exit 1
|
image "$f" "$w" "$h" "$x" "$y" && return 0
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
batorcat() {
|
batorcat() {
|
||||||
file="$1"
|
f=$1
|
||||||
shift
|
w=$2
|
||||||
if command -v bat > /dev/null 2>&1; then
|
if command -v bat > /dev/null 2>&1; then
|
||||||
bat --color=always --style=plain --pager=never "$file" "$@"
|
bat --color=always --style=plain --pager=never --terminal-width "$(($w-2))" "$f"
|
||||||
elif command -v batcat > /dev/null 2>&1; then
|
elif command -v batcat > /dev/null 2>&1; then
|
||||||
batcat --color=always --style=plain --pager=never "$file" "$@"
|
batcat --color=always --style=plain --pager=never --terminal-width "$(($w-2))" "$f"
|
||||||
else
|
else
|
||||||
cat "$file"
|
cat "$f"
|
||||||
fi
|
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}'))"
|
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 "$(printf "%s\n" "$(readlink -f "$1")" | awk '{print tolower($0)}')" in
|
case "$(xdg-mime query filetype "$1")" in
|
||||||
*.md) glow "$1" && exit 0 ;;
|
*/x-bzip-compressed-tar|*/x-compressed-tar) als -- "$1" && exit 0 || echo -e "\e[31matools not installed\e[0m" && exit 1;;
|
||||||
*.xml|*.html) w3m -dump "$1" && exit 0 ;;
|
*/x-7z-compressed|*/vnd.rar|*/x-tar|*/zip|*/x-java-archive|*/x-xz) 7z l "$1" | sed 1,11d && exit 0 || echo -e "\e[31m7zip not installed\e[0m" && exit 1;;
|
||||||
*.[1-8]) man "$1" | col -b && exit 0 ;;
|
*/x-cd-image) iso-info --no-header -l "$1" && exit 0 || echo -e "\e[31mlibcdio-utils not installed\e[0m" && exit 1;;
|
||||||
*.o) nm "$1" && exit 0 ;;
|
*/x-bittorrent) transmission-show "$1" && exit 0 || echo -e "\e[31mtransmission-cli not installed\e[0m" && exit 1;;
|
||||||
|
*/vnd.sun.xml.writer) odt2txt "$1" && exit 0 || echo -e "\e[31modt2txt not installed\e[0m" && exit 1;;
|
||||||
|
*/msword) catdoc "$1" && exit 0 || echo -e "\e[31mcatdoc not installed\e[0m" && exit 1;;
|
||||||
|
*/vnd.openxmlformats-officedocument.wordprocessingml.document) docx2txt < "$1" && exit 0 || echo -e "\e[31mdocx2txt not installed\e[0m" && exit 1;;
|
||||||
|
*/vnd.ms-excel) ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1" | batorcat --language=csv && exit 0 || echo -e "\e[31mgnumeric not installed\e[0m" && exit 1;;
|
||||||
|
*/vnd.openxmlformats-officedocument.spreadsheetml.sheet) ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1" | batorcat --language=csv && exit 0 || echo -e "\e[31mgnumeric not installed\e[0m" && exit 1;;
|
||||||
|
*/epub+zip) [ ! -f "$CACHE" ] && epub-thumbnailer "$1" "$CACHE" 1024; image "$CACHE" "$2" "$3" "$4" "$5" && exit 0 || echo -e "\e[31mepubthumbnailer not installed (https://github.com/marianosimone/epub-thumbnailer)\e[0m" && exit 1;;
|
||||||
|
*/pgp-encrypted) gpg -d -- "$1" && exit 0 || echo -e "\e[31mgpg not installed\e[0m" && exit 1;;
|
||||||
|
*/pkix-cert) openssl x509 -text -noout -in "$1" && exit 0 || echo -e "\e[31mopenssl not installed\e[0m" && exit 1;;
|
||||||
|
image/*) image "$1" "$2" "$3" "$4" "$5" && exit 0;;
|
||||||
|
video/*) video "$1" "$2" "$3" "$4" "$5" && exit 0;;
|
||||||
|
*opendocument*) odt2txt "$1" && exit 0 || echo -e "\e[31modt2txt not installed\e[0m" && exit 1;;
|
||||||
|
*/markdown) glow "$1" && exit 0 || echo -e "\e[31mglow not installed (https://github.com/charmbracelet/glow)\e[0m" && exit 1;;
|
||||||
|
*/html) w3m -dump "$1" && exit 0 || lynx -dump "$1" && exit 0 || echo -e "\e[31neither lynx nor w3m installed\e[0m" && exit 1;;
|
||||||
|
text/*|*/json|*/xml) batorcat "$1" "$2" && exit 0;;
|
||||||
|
*/pdf) [ ! -f "${CACHE}.jpg" ] && pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE"; image "${CACHE}.jpg" "$2" "$3" "$4" "$5" && exit 0 || echo -e "\e[31mpoppler-utils not installed\e[0m" && exit 1;;
|
||||||
esac
|
esac
|
||||||
|
case "$(file -bL --mime-type "$1")" in
|
||||||
case "$(file -bL --mime-type $1)" in
|
text/*) batorcat "$1" "$2" && exit 0;;
|
||||||
application/gzip) tar tzf "$1" ;;
|
|
||||||
application/x-bzip2) tar tjf "$1" ;;
|
|
||||||
application/x-xz) xz --list "$1" ;;
|
|
||||||
application/x-tar) tar tf "$1" ;;
|
|
||||||
application/zip) unzip -l "$1" ;;
|
|
||||||
application/java-archive) unzip -l "$1" ;;
|
|
||||||
application/x-rar) unrar l "$1" ;;
|
|
||||||
application/x-7z-compressed) 7z l "$1" ;;
|
|
||||||
application/x-iso9660-image) iso-info --no-header -l "$1" ;;
|
|
||||||
application/x-bittorrent) transmission-show "$1" ;;
|
|
||||||
application/vnd.sun.xml.writer) odt2txt "$1" ;;
|
|
||||||
application/msword) catdoc "$1" ;;
|
|
||||||
application/vnd.openxmlformats-officedocument.wordprocessingml.document) docx2txt < "$1" ;;
|
|
||||||
application/vnd.ms-excel) ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1" | batorcat --language=csv ;;
|
|
||||||
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet) ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1" | batorcat --language=csv ;;
|
|
||||||
application/epub+zip) [ ! -f "$CACHE" ] && epub-thumbnailer "$1" "$CACHE" 1024; image "$CACHE" "$2" "$3" "$4" "$5" ;;
|
|
||||||
application/pgp-encrypted) gpg -d -- "$1" ;;
|
|
||||||
image/*) image "$1" "$2" "$3" "$4" "$5" ;;
|
|
||||||
video/*) video "$1" "$2" "$3" "$4" "$5" ;;
|
|
||||||
*opendocument*) odt2txt "$1" ;;
|
|
||||||
text/*|*/xml|application/json) batorcat "$1" ;;
|
|
||||||
*/pdf) [ ! -f "${CACHE}.jpg" ] && pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE"; image "${CACHE}.jpg" "$2" "$3" "$4" "$5" ;;
|
|
||||||
*) mediainfo "$1" || exit 1 ;;
|
|
||||||
esac
|
esac
|
||||||
exit 0
|
echo -e "\e[31mNo previewer configured for $(xdg-mime query filetype "$1")\e[0m"
|
||||||
|
mediainfo "$1" && exit 0
|
||||||
|
exit 1
|
||||||
|
|
Loading…
Reference in New Issue