vifmimg 2.4 KB

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