Skip to content

Instantly share code, notes, and snippets.

@mehalter
Created March 3, 2023 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mehalter/57f5579093ceb6167dd2e534285d5642 to your computer and use it in GitHub Desktop.
Save mehalter/57f5579093ceb6167dd2e534285d5642 to your computer and use it in GitHub Desktop.
mimetype based preview script
#! /usr/bin/env sh
case $(file -bL --mime-type "$1") in
cannot\ open*) exit ;;
inode/directory) ls --color=always "$1" ;;
text/html) w3m -O UTF-8 -dump "$1" ;;
text/troff) man ./"$1" ;;
application/gzip | application/x-tar | application/zip | application/x-7z-compressed | application/vnd.rar | application/x-bzip*) bsdtar --list --file "$1" ;;
application/json) jq --color-output . "$1" ;;
audio/* | image/* | application/octet-stream) mediainfo "$1" || exit 1 ;;
*opendocument*) odt2txt "$1" ;;
application/pgp-encrypted) gpg -d -- "$1" ;;
text/* | */xml) bat --style="plain" --color=always "$1" ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment