Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ==> .scripts/vifmimg <==
- #!/usr/bin/env bash
- readonly ID_PREVIEW="preview"
- #AUTO_REMOVE="yes"
- # By enabling this option the script will remove the preview file after it is drawn
- # and by doing so the preview will always be up-to-date with the file.
- # This however, requires more CPU and therefore affects the overall performance.
- if [ -e "$FIFO_UEBERZUG" ]; then
- if [[ "$1" == "draw" ]]; then
- declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
- [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
- [path]="${PWD}/$6") \
- > "$FIFO_UEBERZUG"
- elif [[ "$1" == "videopreview" ]]; then
- echo -e "Loading preview..\nFile: $6"
- [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/"
- [[ ! -f "/tmp${PWD}/$6.png" ]] && ffmpegthumbnailer -i "${PWD}/$6" -o "/tmp${PWD}/$6.png" -s 0 -q 10
- declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
- [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
- [path]="/tmp${PWD}/$6.png") \
- > "$FIFO_UEBERZUG"
- elif [[ "$1" == "gifpreview" ]]; then
- echo -e "Loading preview..\nFile: $6"
- [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/" && convert -coalesce "${PWD}/$6" "/tmp${PWD}/$6/$6.png"
- for frame in $(ls -1 /tmp${PWD}/$6/$6*.png | sort -V); do
- declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
- [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
- [path]="$frame") \
- > "$FIFO_UEBERZUG"
- # Sleep between frames to make the animation smooth.
- sleep .07
- done
- elif [[ "$1" == "pdfpreview" ]]; then
- echo -e "Loading preview..\nFile: $6"
- [[ ! -d "/tmp${PWD}/$6/" ]] && mkdir -p "/tmp${PWD}/$6/"
- [[ ! -f "/tmp${PWD}/$6.png" ]] && pdftoppm -png -singlefile "$6" "/tmp${PWD}/$6"
- declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
- [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
- [path]="/tmp${PWD}/$6.png") \
- > "$FIFO_UEBERZUG"
- elif [[ "$1" == "clear" ]]; then
- declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") \
- > "$FIFO_UEBERZUG"
- [[ ! -z $AUTO_REMOVE ]] && [[ -f "/tmp${PWD}/$6.png" ]] && rm -f "/tmp${PWD}/$6.png"
- [[ ! -z $AUTO_REMOVE ]] && [[ -d "/tmp${PWD}/$6/" ]] && rm -rf "/tmp${PWD}/$6/"
- fi
- fi
- ==> .scripts/vifmimg_old <==
- #!/usr/bin/env bash
- readonly ID_PREVIEW="preview"
- #PLAY_GIF="yes"
- # By enabling this option the GIF will be animated, by leaving it commented like it
- # is now will make the gif previews behave the same way as video previews.
- #AUTO_REMOVE="yes"
- # By enabling this option the script will remove the preview file after it is drawn
- # and by doing so the preview will always be up-to-date with the file.
- # This however, requires more CPU and therefore affects the overall performance.
- # The messy code below is for moving pages in pdf files in the vifm file preview by
- # utilizing the < and > keys which will be bound to `vifmimg inc` or `vifmimg dec`.
- PDF_PAGE_CONFIG="$HOME/.config/vifm/vifmimgpdfpage"
- PDF_FILE_CONFIG="$HOME/.config/vifm/vifmimgpdffile"
- PDF_PAGE=1
- PDF_FILE=""
- # Initialize the variables and required files
- [[ -f "$PDF_PAGE_CONFIG" ]] && PDF_PAGE=$(cat $PDF_PAGE_CONFIG) || touch $PDF_PAGE_CONFIG
- [[ -f "$PDF_FILE_CONFIG" ]] && PDF_FILE=$(cat $PDF_FILE_CONFIG) || touch $PDF_FILE_CONFIG
- # Create temporary working directory if the directory structure doesn't exist
- if [[ ! -d "/tmp$PWD/" ]]; then
- mkdir -p "/tmp$PWD/"
- fi
- function inc() {
- VAL="$(cat $PDF_PAGE_CONFIG)"
- echo "$(expr $VAL + 1)" > $PDF_PAGE_CONFIG
- }
- function dec() {
- VAL="$(cat $PDF_PAGE_CONFIG)"
- echo "$(expr $VAL - 1)" > $PDF_PAGE_CONFIG
- if [[ $VAL -le 0 ]]; then
- echo 0 > $PDF_PAGE_CONFIG
- fi
- }
- function previewclear() {
- declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") \
- > "$FIFO_UEBERZUG"
- }
- function fileclean() {
- if [[ -f "/tmp$PWD/$6.png" ]]; then
- rm -f "/tmp$PWD/$6.png"
- elif [[ -d "/tmp$PWD/$6/" ]]; then
- rm -rf "/tmp$PWD/$6/"
- fi
- }
- function preview() {
- declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
- [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
- [path]="$PWD/$6") \
- > "$FIFO_UEBERZUG"
- }
- function previewvideo() {
- if [[ ! -f "/tmp$PWD/$6.png" ]]; then
- ffmpegthumbnailer -i "$PWD/$6" -o "/tmp$PWD/$6.png" -s 0 -q 10
- fi
- declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
- [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
- [path]="/tmp$PWD/$6.png") \
- > "$FIFO_UEBERZUG"
- }
- function previewepub() {
- if [[ ! -f "/tmp$PWD/$6.png" ]]; then
- epub-thumbnailer "$6" "/tmp$PWD/$6.png" 1024
- fi
- declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
- [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
- [path]="/tmp$PWD/$6.png") \
- > "$FIFO_UEBERZUG"
- }
- function previewgif() {
- if [[ ! -d "/tmp$PWD/$6/" ]]; then
- mkdir -p "/tmp$PWD/$6/"
- convert -coalesce "$PWD/$6" "/tmp$PWD/$6/$6.png"
- fi
- if [[ ! -z "$PLAY_GIF" ]]; then
- for frame in $(ls -1 /tmp$PWD/$6/$6*.png | sort -V); do
- declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
- [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
- [path]="$frame") \
- > "$FIFO_UEBERZUG"
- # Sleep between frames to make the animation smooth.
- sleep .07
- done
- else
- declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
- [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
- [path]="/tmp$PWD/$6/$6-0.png") \
- > "$FIFO_UEBERZUG"
- ==> .scripts/vifmrun <==
- #!/usr/bin/env bash
- export FIFO_UEBERZUG="/tmp/vifm-ueberzug-${PPID}"
- function cleanup {
- rm "$FIFO_UEBERZUG" 2>/dev/null
- pkill -P $$ 2>/dev/null
- }
- pkill -P $$ 2>/dev/null
- rm "$FIFO_UEBERZUG" 2>/dev/null
- mkfifo "$FIFO_UEBERZUG" >/dev/null
- trap cleanup EXIT 2>/dev/null
- tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser bash 2>&1 >/dev/null &
- vifm
- cleanup
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement