dotfiles

My collection of dotfiles
git clone git://git.noxz.tech/dotfiles
Log | Files | Refs

vifmimg (2758B)


      1 #!/bin/sh
      2 readonly ID_PREVIEW="preview"
      3 readonly TMP="/tmp$PWD"
      4 readonly _X="$2"
      5 readonly _Y="$3"
      6 readonly _W="$4"
      7 readonly _H="$5"
      8 
      9 #PLAY_GIF="yes"
     10 #AUTO_REMOVE="yes"
     11 
     12 # exit if required FIFO doesn't exist
     13 [ ! -e "$FIFO_UEBERZUG" ] && exit
     14 
     15 _draw () {
     16 	echo "{                                                                 \
     17 		\"action\"      : \"add\",                                          \
     18 		\"identifier\"  : \"$ID_PREVIEW\",                                  \
     19 		\"x\"           : $_X,                                              \
     20 		\"y\"           : $((_Y + 1)),                                      \
     21 		\"width\"       : $_W,                                              \
     22 		\"height\"      : $_H,                                              \
     23 		\"path\"        : \"$1\"                                            \
     24 	}" > "$FIFO_UEBERZUG"
     25 }
     26 
     27 case "$1" in
     28 draw)
     29 	_draw "$PWD/$6"
     30 	;;
     31 drawmagick)
     32 	[ ! -d "$TMP/$6/" ] && mkdir -p "$TMP/$6/"
     33 	[ ! -f "$TMP/$6.png" ] && convert -resize 200x200 -density 1200 "$PWD/$6" "$TMP/$6.png"
     34 	_draw "$TMP/$6.png"
     35 	;;
     36 drawff)
     37 	[ ! -d "$TMP/$6/" ] && mkdir -p "$TMP/$6/"
     38 	if [ ! -f "$TMP/$6.png" ]; then
     39 		case "$6" in
     40 		*.ff.bz)    bzip2 -d -c "$PWD/$6" | ff2png > "$TMP/$6.png"          ;;
     41 		*.ff.gz)    gzip -d -c "$PWD/$6" | ff2png > "$TMP/$6.png"           ;;
     42 		*.ff.xz)    xz -d -c "$PWD/$6" | ff2png > "$TMP/$6.png"             ;;
     43 		*.ff)       ff2png < "$PWD/$6" > "$TMP/$6.png"                      ;;
     44 		*)          exit                                                    ;;
     45 		esac
     46 		convert -resize 512x512\> "$TMP/$6.png" "$TMP/$6.png"
     47 	fi
     48 	_draw "$TMP/$6.png"
     49 	;;
     50 videopreview)
     51 	[ ! -d "$TMP/$6/" ] && mkdir -p "$TMP/$6/"
     52 	[ ! -f "$TMP/$6.png" ] && ffmpegthumbnailer -i "$PWD/$6" -o "$TMP/$6.png" -s 0 -q 10
     53 	_draw "$TMP/$6.png"
     54 	;;
     55 gifpreview)
     56 	[ ! -d "$TMP/$6/" ] && mkdir -p "$TMP/$6/" && convert -coalesce "$PWD/$6" "$TMP/$6/$6.png"
     57 	if [ -n "$PLAY_GIF" ]; then
     58 		for frame in $(find "$TMP/$6" -name "*.png" | sort -V); do
     59 			_draw "$frame"
     60 			sleep .07
     61 		done
     62 	else
     63 		_draw "$TMP/$6/$6-0.png"
     64 	fi
     65 	;;
     66 epubpreview)
     67 	[ ! -d "$TMP/$6/" ] && mkdir -p "$TMP/$6/"
     68 	[ ! -f "$TMP/$6.png" ] && epub-thumbnailer "$6" "$TMP/$6.png" 512
     69 	_draw "$TMP/$6.png"
     70 	;;
     71 pdfpreview)
     72 	[ ! -d "$TMP/$6/" ] && mkdir -p "$TMP/$6/"
     73 	[ ! -f "$TMP/$6.png" ] && pdftoppm -png -singlefile "$6" "$TMP/$6"
     74 	_draw "$TMP/$6.png"
     75 	;;
     76 clear)
     77 	echo "{                                                                 \
     78 		\"action\"      : \"remove\",                                       \
     79 		\"identifier\"  : \"$ID_PREVIEW\"                                   \
     80 	}" > "$FIFO_UEBERZUG"
     81 	[ -n "$AUTO_REMOVE" ] && [ -f "$TMP/$6.png" ] && rm -f "$TMP/$6.png"
     82 	[ -n "$AUTO_REMOVE" ] && [ -d "$TMP/$6/" ] && rm -rf "$TMP/$6/"
     83 	;;
     84 esac