Advertisement
Guest User

Untitled

a guest
May 30th, 2019
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. ==> .scripts/vifmimg <==
  2. #!/usr/bin/env bash
  3. readonly ID_PREVIEW="preview"
  4.  
  5. #AUTO_REMOVE="yes"
  6. # By enabling this option the script will remove the preview file after it is drawn
  7. # and by doing so the preview will always be up-to-date with the file.
  8. # This however, requires more CPU and therefore affects the overall performance.
  9.  
  10. if [ -e "$FIFO_UEBERZUG" ]; then
  11. if [[ "$1" == "draw" ]]; then
  12. declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
  13. [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
  14. [path]="${PWD}/$6") \
  15. > "$FIFO_UEBERZUG"
  16.  
  17. elif [[ "$1" == "videopreview" ]]; then
  18. echo -e "Loading preview..\nFile: $6"
  19. [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/"
  20. [[ ! -f "/tmp${PWD}/$6.png" ]] && ffmpegthumbnailer -i "${PWD}/$6" -o "/tmp${PWD}/$6.png" -s 0 -q 10
  21. declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
  22. [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
  23. [path]="/tmp${PWD}/$6.png") \
  24. > "$FIFO_UEBERZUG"
  25.  
  26. elif [[ "$1" == "gifpreview" ]]; then
  27. echo -e "Loading preview..\nFile: $6"
  28. [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/" && convert -coalesce "${PWD}/$6" "/tmp${PWD}/$6/$6.png"
  29. for frame in $(ls -1 /tmp${PWD}/$6/$6*.png | sort -V); do
  30. declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
  31. [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
  32. [path]="$frame") \
  33. > "$FIFO_UEBERZUG"
  34. # Sleep between frames to make the animation smooth.
  35. sleep .07
  36. done
  37.  
  38. elif [[ "$1" == "pdfpreview" ]]; then
  39. echo -e "Loading preview..\nFile: $6"
  40. [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/"
  41. [[ ! -f "/tmp${PWD}/$6.png" ]] && pdftoppm -png -singlefile "$6" "/tmp${PWD}/$6"
  42. declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
  43. [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
  44. [path]="/tmp${PWD}/$6.png") \
  45. > "$FIFO_UEBERZUG"
  46.  
  47. elif [[ "$1" == "clear" ]]; then
  48. declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") \
  49. > "$FIFO_UEBERZUG"
  50. [[ ! -z $AUTO_REMOVE ]] && [[ -f "/tmp${PWD}/$6.png" ]] && rm -f "/tmp${PWD}/$6.png"
  51. [[ ! -z $AUTO_REMOVE ]] && [[ -d "/tmp${PWD}/$6/" ]] && rm -rf "/tmp${PWD}/$6/"
  52.  
  53. fi
  54. fi
  55.  
  56.  
  57. ==> .scripts/vifmimg_old <==
  58. #!/usr/bin/env bash
  59. readonly ID_PREVIEW="preview"
  60.  
  61. #PLAY_GIF="yes"
  62. # By enabling this option the GIF will be animated, by leaving it commented like it
  63. # is now will make the gif previews behave the same way as video previews.
  64.  
  65. #AUTO_REMOVE="yes"
  66. # By enabling this option the script will remove the preview file after it is drawn
  67. # and by doing so the preview will always be up-to-date with the file.
  68. # This however, requires more CPU and therefore affects the overall performance.
  69.  
  70. # The messy code below is for moving pages in pdf files in the vifm file preview by
  71. # utilizing the < and > keys which will be bound to `vifmimg inc` or `vifmimg dec`.
  72. PDF_PAGE_CONFIG="$HOME/.config/vifm/vifmimgpdfpage"
  73. PDF_FILE_CONFIG="$HOME/.config/vifm/vifmimgpdffile"
  74. PDF_PAGE=1
  75. PDF_FILE=""
  76. # Initialize the variables and required files
  77. [[ -f "$PDF_PAGE_CONFIG" ]] && PDF_PAGE=$(cat $PDF_PAGE_CONFIG) || touch $PDF_PAGE_CONFIG
  78. [[ -f "$PDF_FILE_CONFIG" ]] && PDF_FILE=$(cat $PDF_FILE_CONFIG) || touch $PDF_FILE_CONFIG
  79.  
  80.  
  81. # Create temporary working directory if the directory structure doesn't exist
  82. if [[ ! -d "/tmp$PWD/" ]]; then
  83. mkdir -p "/tmp$PWD/"
  84. fi
  85.  
  86. function inc() {
  87. VAL="$(cat $PDF_PAGE_CONFIG)"
  88. echo "$(expr $VAL + 1)" > $PDF_PAGE_CONFIG
  89. }
  90.  
  91. function dec() {
  92. VAL="$(cat $PDF_PAGE_CONFIG)"
  93. echo "$(expr $VAL - 1)" > $PDF_PAGE_CONFIG
  94. if [[ $VAL -le 0 ]]; then
  95. echo 0 > $PDF_PAGE_CONFIG
  96. fi
  97. }
  98.  
  99. function previewclear() {
  100. declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") \
  101. > "$FIFO_UEBERZUG"
  102. }
  103.  
  104. function fileclean() {
  105. if [[ -f "/tmp$PWD/$6.png" ]]; then
  106. rm -f "/tmp$PWD/$6.png"
  107. elif [[ -d "/tmp$PWD/$6/" ]]; then
  108. rm -rf "/tmp$PWD/$6/"
  109. fi
  110. }
  111.  
  112. function preview() {
  113. declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
  114. [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
  115. [path]="$PWD/$6") \
  116. > "$FIFO_UEBERZUG"
  117. }
  118.  
  119. function previewvideo() {
  120. if [[ ! -f "/tmp$PWD/$6.png" ]]; then
  121. ffmpegthumbnailer -i "$PWD/$6" -o "/tmp$PWD/$6.png" -s 0 -q 10
  122. fi
  123. declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
  124. [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
  125. [path]="/tmp$PWD/$6.png") \
  126. > "$FIFO_UEBERZUG"
  127. }
  128.  
  129. function previewepub() {
  130. if [[ ! -f "/tmp$PWD/$6.png" ]]; then
  131. epub-thumbnailer "$6" "/tmp$PWD/$6.png" 1024
  132. fi
  133. declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
  134. [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
  135. [path]="/tmp$PWD/$6.png") \
  136. > "$FIFO_UEBERZUG"
  137. }
  138.  
  139. function previewgif() {
  140. if [[ ! -d "/tmp$PWD/$6/" ]]; then
  141. mkdir -p "/tmp$PWD/$6/"
  142. convert -coalesce "$PWD/$6" "/tmp$PWD/$6/$6.png"
  143. fi
  144. if [[ ! -z "$PLAY_GIF" ]]; then
  145. for frame in $(ls -1 /tmp$PWD/$6/$6*.png | sort -V); do
  146. declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
  147. [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
  148. [path]="$frame") \
  149. > "$FIFO_UEBERZUG"
  150. # Sleep between frames to make the animation smooth.
  151. sleep .07
  152. done
  153. else
  154. declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
  155. [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
  156. [path]="/tmp$PWD/$6/$6-0.png") \
  157. > "$FIFO_UEBERZUG"
  158.  
  159. ==> .scripts/vifmrun <==
  160. #!/usr/bin/env bash
  161. export FIFO_UEBERZUG="/tmp/vifm-ueberzug-${PPID}"
  162.  
  163. function cleanup {
  164. rm "$FIFO_UEBERZUG" 2>/dev/null
  165. pkill -P $$ 2>/dev/null
  166. }
  167. pkill -P $$ 2>/dev/null
  168. rm "$FIFO_UEBERZUG" 2>/dev/null
  169. mkfifo "$FIFO_UEBERZUG" >/dev/null
  170. trap cleanup EXIT 2>/dev/null
  171. tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser bash 2>&1 >/dev/null &
  172.  
  173. vifm
  174. cleanup
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement