Something went wrong. Try again.
Something went wrong. Try again.
1.3 kB · 72 lines
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273#!/bin/bash
set -euf
declare ftdeclare f="${1}"declare w="${2}"declare h="${3}"declare x="${4}"declare y="${5}"
command_exists() { type "${1}" >/dev/null 2>&1}
has_kitty_protocol() { test -z "${TMUX:-}" && test -n "${KITTY_PID:-}"}
preview_image() { if has_kitty_protocol; then kitty +kitten icat --silent --stdin no --transfer-mode file --place "${w}x${h}@${x}x${y}" "${f}" < /dev/null > /dev/tty exit 1 fi
case "${f}" in *.jpg|*.jpeg|*.png) if command_exists chafa; then chafa --colors=256 "${f}" elif command_exists viu; then echo viu -w "${w}" "${f}" fi ;; esac}
preview_video() { echo "Not Implemented!" # if has_kitty_protocol; then # kitty +icat --silent --transfer-mode file --place "${w}x${h}@${x}x${y}" "$(thumbnailer "$f")" # exit 1 # fi}
case "${f}" in *.tar*) tar tf "${f}" ;; *.zip) unzip -l "${f}" ;; *.rar) unrar l "${f}" ;; *.7z) 7z l -p "${f}" ;; *.pdf) pdftotext "${f}" - ;; *) ft="$(file -Lb --mime-type "$f")" if [[ "${ft}" =~ ^image ]]; then preview_image elif [[ "${ft}" =~ ^video ]]; then preview_video else unset COLORTERM bat --color=always --line-range=0:"${w}" --paging=never --plain "${f}" fi ;;esac