Created
March 3, 2023 14:14
-
-
Save mehalter/57f5579093ceb6167dd2e534285d5642 to your computer and use it in GitHub Desktop.
mimetype based preview script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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