Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- [[ -z $1 ]] && exit
- origin="$1"
- filename="$origin"
- mime=$(file -b --mime-type "$origin")
- # determine compression
- case $mime in
- application/x-gzip) CAT="gzip -dc" ;;
- application/x-bzip*) CAT="bzip2 -dc" ;;
- application/x-xz) CAT="xz -dc" ;;
- *) CAT="cat" ;;
- esac
- # uncompress
- if [[ $CAT != cat ]]; then
- mime=$(file -bz --mime-type "$origin")
- if [[ $mime != application/x-tar && $mime != application/x-cpio ]]; then
- filename=$(mktemp --tmpdir XXXXXXXXXX)
- $CAT "$origin" > $filename
- fi
- fi
- # show file content
- case $mime in
- audio/*)
- echo "$origin"
- mtag "$filename"
- ;;
- video/*)
- echo "$origin"
- ffprobe "$filename" | tail -n +12
- ;;
- image/*)
- if [[ $mime == image/vnd.djvu ]]; then
- djvused -e print-pure-txt "$filename"
- else
- echo "$origin"
- gm identify "$1"
- exiv2 print "$1"
- fi
- ;;
- text/*)
- [[ $(tput colors) -eq 256 ]] && fmt="xterm256" || fmt="ansi"
- case $mime in
- text/html) elinks -dump "$filename" ;;
- text/troff) groff -T utf8 -mandoc "$filename" ;;
- *) highlight --force -s candy -O $fmt "$filename" ;;
- esac
- ;;
- application/x-tar)
- if [[ $filename == *.ipkg ]]; then
- chkpkg -p "$filename"
- else
- $CAT "$filename" | tar -vt
- fi
- ;;
- application/x-zip)
- unzip -v "$filename"
- ;;
- application/x-rar)
- unrar l "$filename"
- ;;
- application/pdf)
- pdftotext -q "$filename" -
- ;;
- application/postscript)
- ps2ascii "$filename"
- ;;
- application/vnd.oasis.opendocument.text)
- odt2txt "$filename"
- ;;
- application/msword|application/vnd.ms-office)
- catdoc "$filename"
- ;;
- *)
- $CAT "$filename"
- ;;
- esac
- # cleanup
- [[ $filename != $origin ]] && rm -r $filename
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement