dotfiles

andersuno dotfiles
git clone git://git.andersuno.nu/dotfiles.git
Log | Files | Refs | README

vifmimg (2492B)


      1 #!/usr/bin/env bash
      2 readonly ID_PREVIEW="preview"
      3 
      4 #AUTO_REMOVE="yes"
      5 # By enabling this option the script will remove the preview file after it is drawn
      6 # and by doing so the preview will always be up-to-date with the file.
      7 # This however, requires more CPU and therefore affects the overall performance.
      8 
      9 if [ -e "$FIFO_UEBERZUG" ]; then
     10     if [[ "$1" == "draw" ]]; then
     11         declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
     12                            [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
     13                            [path]="${PWD}/$6") \
     14             > "$FIFO_UEBERZUG"
     15 
     16     elif [[ "$1" == "videopreview" ]]; then
     17         echo -e "Loading preview..\nFile: $6"
     18         [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/"
     19         [[ ! -f "/tmp${PWD}/$6.png" ]] && ffmpegthumbnailer -i "${PWD}/$6" -o "/tmp${PWD}/$6.png" -s 0 -q 10
     20         declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
     21                            [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
     22                            [path]="/tmp${PWD}/$6.png") \
     23             > "$FIFO_UEBERZUG"
     24 
     25     elif [[ "$1" == "gifpreview" ]]; then
     26         echo -e "Loading preview..\nFile: $6"
     27         [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/" && convert -coalesce "${PWD}/$6" "/tmp${PWD}/$6/$6.png"
     28         for frame in $(ls -1 /tmp${PWD}/$6/$6*.png | sort -V); do
     29            declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
     30                            [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
     31                            [path]="$frame") \
     32             > "$FIFO_UEBERZUG"
     33             # Sleep between frames to make the animation smooth.
     34             sleep .07
     35         done
     36 
     37     elif [[ "$1" == "pdfpreview" ]]; then
     38         echo -e "Loading preview..\nFile: $6"
     39         [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/"
     40         [[ ! -f "/tmp${PWD}/$6.png" ]] && pdftoppm -png -singlefile "$6" "/tmp${PWD}/$6"
     41         declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
     42                            [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
     43                            [path]="/tmp${PWD}/$6.png") \
     44             > "$FIFO_UEBERZUG"
     45 
     46     elif [[ "$1" == "clear" ]]; then
     47         declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") \
     48             > "$FIFO_UEBERZUG"
     49         [[ ! -z $AUTO_REMOVE ]] && [[ -f "/tmp${PWD}/$6.png" ]] && rm -f "/tmp${PWD}/$6.png"
     50         [[ ! -z $AUTO_REMOVE ]] && [[ -d "/tmp${PWD}/$6/" ]] && rm -rf "/tmp${PWD}/$6/"
     51 
     52     fi
     53 fi