*nohtml*

config/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 # 7    | image      | Display the file directly as an image
  13 
  14 path=$1  width=$2
  15 cache=$4 image=$5
  16 
  17 ext=${path##*.}
  18 mime=$(file -Lb --mime-type "$path")
  19 
  20 mkdir -p ${cache%/*}
  21 
  22 case $path in
  23     */Mail/*) frm -Sq "$path" | fmt -w $width && exit 5;;
  24 esac
  25 
  26 [[ $image == True ]] &&
  27 case ${ext,,} in
  28     ttf|otf) convert "$path" "$cache" && exit 6;;
  29         swf) gnash-thumbnailer "$path"  "$cache" 512 && exit 6;;
  30         pdf) pdftoppm -singlefile -jpeg "$path" > "$cache" && exit 6;;
  31 
  32       svg) inkscape "$path" -e "$cache" && exit 6;;
  33       xcf) xcf2png  "$path" -o "$cache" && exit 6;;
  34       kra) unzip -p "$path" preview.png > "$cache" && exit 6;;
  35     blend) blender-thumbnailer.py "$path" "$cache" && exit 6;;
  36 esac
  37 
  38 case ${ext,,} in
  39      odt) odt2txt "$path" && exit 5;;
  40     json) jq -C . "$path" && exit 5;;
  41     mbox) frm -Sn "$path" | tac && exit 5;;
  42      gpg) gpg -d  "$path" && exit 5 || exit 1;;
  43      svg) highlight -O ansi "$path" && exit 5 || exit 2;;
  44       db) sqlite3 "$path" .schema | highlight -O ansi -WS sql && exit 5;;
  45 
  46      torrent) transmission-show "$path" && exit 5;;
  47      cfg|cnf) highlight -O ansi -S conf "$path" && exit 5 || exit 2;;
  48     opml|dae) highlight -O ansi -S xml  "$path" && exit 5 || exit 2;;
  49 
  50     godot|import|tres|tscn) highlight -O ansi -S ini "$path" && exit 5 || exit 2;;
  51 esac
  52 
  53 [[ $image == True ]] &&
  54 case $mime in
  55     image/*) exit 7;;
  56     video/*) ffmpegthumbnailer -i "$path" -o "$cache" -s 0 && exit 6;;
  57 esac
  58 
  59 case $mime in
  60     image/*) LANG= exiv2 "$path" && exit 5;;
  61     text/*|*/xml) highlight -O ansi "$path" && exit 5 || exit 2;;
  62     audio/*|video/*) mediainfo "$path" | sed 's/\s\{19\}//' && exit 5;;
  63 esac
  64 
  65 exit 1