Advertisement
ananas

lessopen filter

Nov 1st, 2013
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.03 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. [[ -z $1 ]] && exit
  4.  
  5. origin="$1"
  6. filename="$origin"
  7. mime=$(file -b --mime-type "$origin")
  8.  
  9. # determine compression
  10. case $mime in
  11.     application/x-gzip) CAT="gzip -dc" ;;
  12.     application/x-bzip*) CAT="bzip2 -dc" ;;
  13.     application/x-xz) CAT="xz -dc" ;;
  14.     *) CAT="cat" ;;
  15. esac
  16.  
  17. # uncompress
  18. if [[ $CAT != cat ]]; then
  19.     mime=$(file -bz --mime-type "$origin")
  20.     if [[ $mime != application/x-tar && $mime != application/x-cpio ]]; then
  21.         filename=$(mktemp --tmpdir XXXXXXXXXX)
  22.         $CAT "$origin" > $filename
  23.     fi
  24. fi
  25.  
  26. # show file content
  27. case $mime in
  28.     audio/*)
  29.         echo "$origin"
  30.         mtag "$filename"
  31.         ;;
  32.     video/*)
  33.         echo "$origin"
  34.         ffprobe "$filename" | tail -n +12        
  35.         ;;
  36.     image/*)
  37.         if [[ $mime == image/vnd.djvu ]]; then
  38.             djvused -e print-pure-txt "$filename"
  39.         else
  40.             echo "$origin"
  41.             gm identify "$1"
  42.             exiv2 print "$1"
  43.         fi
  44.         ;;
  45.     text/*)
  46.         [[ $(tput colors) -eq 256 ]] && fmt="xterm256" || fmt="ansi"
  47.         case $mime in
  48.             text/html) elinks -dump "$filename" ;;
  49.             text/troff) groff -T utf8 -mandoc "$filename" ;;
  50.             *) highlight --force -s candy -O $fmt "$filename" ;;
  51.         esac
  52.         ;;
  53.     application/x-tar)
  54.         if [[ $filename == *.ipkg ]]; then
  55.             chkpkg -p "$filename"
  56.         else
  57.             $CAT "$filename" | tar -vt
  58.         fi
  59.         ;;
  60.     application/x-zip)
  61.         unzip -v "$filename"
  62.         ;;
  63.     application/x-rar)
  64.         unrar l "$filename"
  65.         ;;
  66.     application/pdf)
  67.         pdftotext -q "$filename" -
  68.         ;;
  69.     application/postscript)
  70.         ps2ascii "$filename"
  71.         ;;
  72.     application/vnd.oasis.opendocument.text)
  73.         odt2txt "$filename"
  74.         ;;
  75.     application/msword|application/vnd.ms-office)
  76.         catdoc "$filename"
  77.         ;;
  78.     *)
  79.         $CAT "$filename"
  80.         ;;
  81. esac
  82.  
  83. # cleanup
  84. [[ $filename != $origin ]] && rm -r $filename
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement