These are some guides for various use.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
6.1 KiB

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