#!/bin/sh case "$1" in # First check common extensions *.wav|*.mp3|*.flac|*.m4a|*.ape|*.ac3|*.oga|*.ogg|*.ogx|*.spx|*.dsf|*.opus|*.dff|*.wma|*.wvc|*.wv) exiftool "$1" ;; *.pdf) mutool draw -F txt -i -- "$1" 1-10 || pdftotext -l 10 -nopgbrk -q -- "$1" - || exiftool "$1" ;; *.ps) pstotext "$1" || ps2ascii "$1" ;; *.epub|*.fb2) pandoc -s -t markdown -- "$1" ;; *.djvu) djvutxt "$1" || exiftool "$1" ;; *.html|*.xhtml|*.htm) pandoc -s -t markdown -- "$1" || lynx -dump -- "$1" ;; *.mkd|*.md|*.markdown) glow -s ~/.config/glow/styles/{{ theme }}.json "$1" || lowdown -t term "$1" || mdcat "$1" ;; *.ipynb) notedown --from notebook "$1" --to markdown | pandoc -f markdown -t plain ;; *.torrent) dumptorrent -v "$1" || transmission-show -- "$1" ;; *.zip|*.war|*.ear|*.oxt|*.tar|*.tgz|*.tar.gz|*.tbz2|*.tar.bz2|*.tar.txz|*.txz|*.rar|*.7z|*.ace|*.rpm|*.deb|*.xbps|*.Z|*.lzo|*.lzma|*.lha|*.cpio|*.jar|*.lz|*.lzh) bsdtar -tf "$1" ;; *.iso) isoinfo -l -i "$1" ;; *.doc) catdoc -- "$1" || pandoc -s -t markdown -- "$1" ;; *.docx) pandoc -s -t markdown -- "$1" ;; *.odt|*.ott|*.stw|*.sxc) pandoc -s -t markdown -- "$1" || odt2txt "$1" ;; *.json|*.jsonc) gojq -C . "$1" || jaq --color always . "$1" || jq . "$1" || python3 -m json.tool -- "$1" ;; *.[1-8]) man "$1" | col -b ;; # Then fallback to mimetypes *) mimetype=$(file --dereference --brief --mime-type -- "$1") case "$mimetype" in inode/directory) # Don't preview the inode ../ if [ -z "${1##*/..*}" ]; then echo "" else lsd -1FAL --group-dirs first --icon always --color always "$1" fi ;; application/zip|application/x-tar*|application/*-compressed-tar\ |application/vnd.rar|application/x-7z-compressed|application/x-xz*\ |application/x-bzip|application/gzip|application/zstd|application/zlib\ |application/x-lzma|application/x-lzip|application/x-lha|application/x-lhz\ |application/x-lzop|application/x-lz4|application/x-lrzip) bsdtar -tf "$1" ;; application/json) gojq -C . "$1" || jaq --color always . "$1" || jq . "$1" || python3 -m json.tool -- "$1" || bat --style=plain --color=always "$1" ;; text/*|application/javascript) bat --style=plain --color=always "$1" ;; *) echo '----- File Type Classification -----' && file --dereference --brief -- "$1" ;; esac ;; esac