ranger/scope.sh

   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 mkdir -p $(dirname $cache)
  20 
  21 case "$(echo "${path##*.}" | tr '[:upper:]' '[:lower:]')" in
  22     torrent) transmission-show "$path" && exit || exit 1;;
  23     ttf|otf) convert "$path" "$cache" && exit 6 || exit 1;;
  24     blend) /usr/share/blender/scripts/blender-thumbnailer.py "$path" "$cache" && convert -scale 512 "$cache" "$cache" && exit 6 || exit 1;;
  25     swf) gnash-thumbnailer "$path" "$cache" 512 && exit 6 || exit 1;;
  26     pdf) evince-thumbnailer "$path" "$cache" -s 1024 && exit 6 || exit 1;;
  27     xcf) gnome-xcf-thumbnailer "$path" "$cache" && exit 6 || exit 1;;
  28 esac
  29 
  30 case "$(file -Lb --mime-type "$path")" in
  31     text/*|*/xml) highlight "$path" -O ansi && exit || exit 2;;
  32     audio/*) mediainfo "$path" | sed 's/ \+:/:/;' && exit || exit 1;;
  33     image/*) convert "$path"[0] "$cache" && exit 6 || exit 1;;
  34     video/*) ffmpegthumbnailer -i "$path" -o "$cache" -s 0 && exit 6 || exit 1;;
  35     */x-dosexec) gnome-exe-thumbnailer "$path" "$cache" && convert -scale 256 "$cache" "$cache" && exit 6 || exit 1;;
  36 esac
  37 
  38 exit 1
  39