1 #!/bin/bash
   2 # Meanings of exit codes:
   3 # code | meaning    | action of ranger
   4 # -----+------------+-------------------------------------------
   5 # 0    | success    | Success. Display stdout as preview
   6 # 1    | no preview | Failure. Display no preview at all
   7 # 2    | plain text | Display the plain content of the file
   8 # 3    | fix width  | Success. Don't reload when width changes
   9 # 4    | fix height | Success. Don't reload when height changes
  10 # 5    | fix both   | Success. Don't ever reload
  11 # 6    | image      | Success. Display the image $cache points to as an image preview
  12 
  13 path="$1"
  14 cache="$4"
  15 
  16 width="$2"
  17 height="$3"
  18 
  19 ext=${path##*.}
  20 ext=${ext,,}
  21 mime=$(file -Lb --mime-type "$path")
  22 
  23 mkdir -p $(dirname $cache)
  24 
  25 case $ext in
  26     ttf|otf) convert "$path" "$cache" && exit 6;;
  27     swf) gnash-thumbnailer "$path" "$cache" 512 && exit 6;;
  28     pdf) evince-thumbnailer "$path" "$cache" -s 1024 && exit 6;;
  29 
  30     xcf) xcf2png "$path" -o "$cache" && exit 6;;
  31     kra) unzip -p "$path" preview.png > "$cache" && exit 6;;
  32     blend) /usr/share/blender/scripts/blender-thumbnailer.py "$path" "$cache" && exit 6;;
  33 
  34     json) jq -C '' "$path" && exit;;
  35     mbox) frm -S "$path"; true && exit;;
  36     torrent) transmission-show "$path" && exit;;
  37     db) sqlite3 "$path" .schema | highlight -O ansi -WS sql && exit;;
  38 esac
  39 
  40 case $mime in
  41     text/*|*/xml) highlight "$path" -O ansi && exit || exit 2;;
  42 
  43     image/*) convert "$path"[0] "$cache" && exit 6;;
  44     audio/*) mediainfo "$path" | sed 's/\s\{19\}//' && exit;;
  45     video/*) ffmpegthumbnailer -i "$path" -o "$cache" -s 0 && exit 6;;
  46 
  47     */x-dosexec) gnome-exe-thumbnailer "$path" "$cache" && exit 6;;
  48 esac
  49 
  50 exit 1
[raw]