#!/bin/sh if [ -d "$1" ]; then if [ -x /bin/eza ] || [ -x /usr/bin/eza ]; then eza -alhF --group-directories-first --color=always --icons -- "$1" else ls -lhAF --group-directories-first --color -- "$1" fi readme="$(find "$1" -maxdepth 1 -name "README.*" | head -1)" [ -n "$readme" ] && preview "$readme" exit fi alias highlight='highlight --out-format=ansi' case "$1" in '') echo "preview: file name required" >&2; exit 1 ;; *.html) w3m -dump "$1" ;; *.md) glow -s dark --width="${FZF_PREVIEW_COLUMNS:-"$(tput cols)"}" "$1" ;; # *.vim) highlight --syntax=vim --replace-tabs=2 -- "$1" ;; *.js|*.vim|*.lua) highlight -- "$1" ;; *.txt|*.description|*.srt) cat -- "$1" ;; *.png|*.jpg|*.jpeg|*.webp|*.mp3|*.ogg|*.mp4|*.mkv|*.webm) mediainfo -- "$1" ;; *.info.json) jq -C . "$1" ;; *.json|*.ipynb) highlight --syntax=json -- "$1" ;; *.tgz|*.tar.gz) tar tzf "$1" ;; *.tar.bz2|*.tbz2) tar tjf "$1" ;; *.tar.txz|*.txz) xz --list "$1" ;; *.tar) tar tf "$1" ;; *.zip|*.jar|*.war|*.ear|*.oxt) unzip -l "$1" ;; *.rar) unrar l "$1" ;; *.7z) 7z l "$1" ;; *.zst) zstdcat "$1" ;; *.[1-8]) man "$1" | col -b ;; *.o) nm "$1" ;; *.torrent) transmission-show "$1" ;; *.iso) iso-info --no-header -l "$1" ;; *odt|*.ods|*.odp|*.sxw) odt2txt "$1" ;; *.doc) catdoc "$1" ;; *.docx) docx2txt "$1" - ;; # *.csv) sed s/,/\\n/g "$1" ;; *) filetype=$(file --dereference --brief --mime-type "$1") case $filetype in *html) w3m -dump "$1" ;; text/markdown) glow -s dark -w "$(tput cols)" "$1" ;; application/json) highlight --syntax=json --replace-tabs=2 -- "$1" ;; text/*) highlight --force -- "$1" ;; audio/*|video/*|image/*) mediainfo -- "$1" ;; *xz) xz --list "$1" ;; *zip|*tar*|*7z*|*bzip2) atool --list -- "$1" ;; *opendocument*) odt2txt "$1" ;; application/pgp-encrypted) gpg -d -- "$1" ;; *) file -b "$1" ;; esac ;; esac