ueberzug&vifm: ready for new version

master
tiyn 1 year ago
parent fd29c9e82a
commit ea1882895c

@ -171,10 +171,9 @@ command! reload :write | restart
" PDF " PDF
filextype *.pdf zathura %c %i &, apvlv %c, xpdf %c filextype *.pdf zathura %c %i &, apvlv %c, xpdf %c
fileviewer *.pdf fileviewer *.pdf
\ vifmimg pdfpreview %px %py %pw %ph %c \ vifmimg pdf %px %py %pw %ph %c
\ %pc \ %pc
\ vifmimg clear \ vifmimg clear
"\ pdftotext -nopgbrk %c -
" CSV " CSV
filetype *.csv,*.xlsx,*.sc sc-im %f filetype *.csv,*.xlsx,*.sc sc-im %f
@ -192,11 +191,19 @@ filextype *.djvu
\ zathura %f, \ zathura %f,
\ {View in apvlv} \ {View in apvlv}
\ apvlv %f, \ apvlv %f,
fileviewer *.djvu
\ vifmimg djvu %px %py %pw %ph %c
\ %pc
\ vifmimg clear
" epub " epub
filextype *.epub filextype *.epub
\ {View in zathura} \ {View in zathura}
\ zathura %f, \ zathura %f,
fileviewer *.epub
\ vifmimg epub %px %py %pw %ph %c
\ %pc
\ vifmimg clear
" svg " svg
filextype *.svg filextype *.svg
@ -209,8 +216,10 @@ filetype *.wav,*.mp3,*.flac,*.m4a,*.wma,*.ape,*.ac3,*.og[agx],*.spx,*.opus
\ ffplay -nodisp -autoexit %c, \ ffplay -nodisp -autoexit %c,
\ {Play using MPlayer} \ {Play using MPlayer}
\ mplayer %f, \ mplayer %f,
fileviewer *.mp3 mp3info fileviewer <audio/*>
fileviewer *.flac soxi \ vifmimg audio %px %py %pw %ph %c
\ %pc
\ vifmimg clear
" Video " Video
filextype *.avi,*.mp4,*.wmv,*.dat,*.3gp,*.ogv,*.mkv,*.mpg,*.mpeg,*.vob, filextype *.avi,*.mp4,*.wmv,*.dat,*.3gp,*.ogv,*.mkv,*.mpg,*.mpeg,*.vob,
@ -218,13 +227,10 @@ filextype *.avi,*.mp4,*.wmv,*.dat,*.3gp,*.ogv,*.mkv,*.mpg,*.mpeg,*.vob,
\*.as[fx] \*.as[fx]
\ {View using mpv} \ {View using mpv}
\ mpv --fs %f, \ mpv --fs %f,
fileviewer *.avi,*.mp4,*.wmv,*.dat,*.3gp,*.ogv,*.mkv,*.mpg,*.mpeg,*.vob, fileviewer <video/*>
\*.fl[icv],*.m2v,*.mov,*.webm,*.ts,*.mts,*.m4v,*.r[am],*.qt,*.divx, \ vifmimg video %px %py %pw %ph %c
\*.as[fx]
\ vifmimg videopreview %px %py %pw %ph %c
\ %pc \ %pc
\ vifmimg clear \ vifmimg clear
"\ ffprobe -pretty %c 2>&1
" Web " Web
filextype *.html,*.htm filextype *.html,*.htm
@ -232,6 +238,12 @@ filextype *.html,*.htm
\ firefox %f &, \ firefox %f &,
filetype *.html,*.htm links, lynx filetype *.html,*.htm links, lynx
" Font
fileviewer <font/*>
\ vifmimg font %px %py %pw %ph %c
\ %pc
\ vifmimg clear
" Object " Object
filetype *.o nm %f | less filetype *.o nm %f | less
@ -243,14 +255,10 @@ fileviewer *.[1-8] man ./%c | col -b
filextype *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm,*.webp filextype *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm,*.webp
\ {View in sxiv} \ {View in sxiv}
\ sxiv -ia %c %d &, \ sxiv -ia %c %d &,
fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm,*.webp fileviewer <image/*>
\ vifmimg draw %px %py %pw %ph %c \ vifmimg draw %px %py %pw %ph %c
\ %pc \ %pc
\ vifmimg clear \ vifmimg clear
fileviewer *.gif
\ vifmimg gifpreview %px %py %pw %ph %c
\ %pc
\vifmimg clear
" OpenRaster " OpenRaster
filextype *.ora filextype *.ora

@ -1,167 +1,56 @@
#!/usr/bin/env bash #!/bin/sh
readonly ID_PREVIEW="preview"
#PLAY_GIF="yes" PCACHE="$HOME/.cache/vifm/thumbnail.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$PWD/$6")" | sha256sum)"
# By enabling this option the GIF will be animated, by leaving it commented like it export PCACHE="${PCACHE%% *}"
# is now will make the gif previews behave the same way as video previews.
#AUTO_REMOVE="yes" pclear() {
# By enabling this option the script will remove the preview file after it is drawn printf '{"action": "remove", "identifier": "vifm-preview"}\n' > "$FIFO_UEBERZUG"
# 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`.
# by cirala, checkout github.com/cirala/vifmimg
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() { image() {
if [[ ! -f "/tmp$PWD/$6.png" ]]; then printf '{"action": "add", "identifier": "vifm-preview", "x": "%s", "y": "%s", "width": "%s", "height": "%s", "scaler": "contain", "path": "%s"}\n' "$2" "$3" "$4" "$5" "$6" > "$FIFO_UEBERZUG"
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 previewaudio() { main() {
if [[ ! -f "/tmp${PWD}/$6.png" ]]; then
ffmpeg -i "$6" "/tmp${PWD}/$6.png" -y &> /dev/null
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"
fi
}
function previewpdf() {
if [[ ! "$6" == "$PDF_FILE" ]]; then
PDF_PAGE=1
echo 1 > $PDF_PAGE_CONFIG
rm -f "/tmp$PWD/$6.png"
fi
if [[ ! "$PDF_PAGE" == "1" ]] && [[ -f "/tmp$PWD/$6.png" ]]; then
rm -f "/tmp$PWD/$6.png"
fi
if [[ ! -f "/tmp$PWD/$6.png" ]]; then
pdftoppm -png -f $PDF_PAGE -singlefile "$6" "/tmp$PWD/$6"
fi
echo "$6" > $PDF_FILE_CONFIG
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 previewmagick() {
if [[ ! -f "/tmp$PWD/$6.png" ]]; then
convert -thumbnail $(identify -format "%wx%h" "$6") "$PWD/$6" "/tmp$PWD/$6.png"
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 main() {
case "$1" in case "$1" in
"inc") inc "$@" ;; "clear")
"dec") dec "$@" ;; pclear "$@"
"clear") previewclear "$@" ;; ;;
"clean") fileclean "$@" ;; "draw")
"draw") preview "$@" ;; FILE="$PWD/$6"
"videopreview") previewvideo "$@" ;; image "$1" "$2" "$3" "$4" "$5" "$FILE"
"epubpreview") previewepub "$@" ;; ;;
"gifpreview") previewgif "$@" ;; "video")
"pdfpreview") previewpdf "$@" ;; [ ! -f "$PCACHE" ] && \
"magickpreview") previewmagick "$@" ;; ffmpegthumbnailer -i "$6" -o "${PCACHE}.jpg" -s 0 -q 5
"audiopreview") previewaudio "$@" ;; image "$1" "$2" "$3" "$4" "$5" "${PCACHE}.jpg"
"*") echo "Unknown command: '$@'" ;; ;;
"epub")
[ ! -f "$PCACHE" ] && \
epub-thumbnailer "$6" "$PCACHE" 1024
image "$1" "$2" "$3" "$4" "$5" "$PCACHE"
;;
"pdf")
[ ! -f "${PCACHE}.jpg" ] && \
pdftoppm -jpeg -f 1 -singlefile "$6" "$PCACHE"
image "$1" "$2" "$3" "$4" "$5" "${PCACHE}.jpg"
;;
"djvu")
[ ! -f "${PCACHE}.jpg" ] && \
ddjvu -format=tiff -quality=90 -page=1 "$6" "$PCACHE.jpg"
image "$1" "$2" "$3" "$4" "$5" "${PCACHE}.jpg"
;;
"audio")
[ ! -f "${PCACHE}.jpg" ] && \
ffmpeg -hide_banner -i "$6" "${PCACHE}.jpg" -y >/dev/null
image "$1" "$2" "$3" "$4" "$5" "${PCACHE}.jpg"
;;
"font")
[ ! -f "${PCACHE}.jpg" ] && \
fontpreview -i "$6" -o "${PCACHE}.jpg"
image "$1" "$2" "$3" "$4" "$5" "${PCACHE}.jpg"
;;
*)
esac esac
} }
main "$@" main "$@"

@ -1,23 +1,21 @@
#!/usr/bin/env bash #!/bin/sh
# by cirala, checkout github.com/cirala/vifmimg if [ -z "$(command -v vifm)" ]; then
printf "vifm isn't installed on your system!\n"
export FIFO_UEBERZUG="/tmp/vifm-ueberzug-${PPID}" exit 1
elif [ -z "$(command -v ueberzug)" ]; then
if [ ! -f "/usr/bin/ueberzug" ]; then exec vifm "$@"
vifm else
exit cleanup() {
exec 3>&-
rm "$FIFO_UEBERZUG"
}
[ ! -d "$HOME/.cache/vifm" ] && mkdir -p "$HOME/.cache/vifm"
export FIFO_UEBERZUG="$HOME/.cache/vifm/ueberzug-${$}"
mkfifo "$FIFO_UEBERZUG"
ueberzug layer -s <"$FIFO_UEBERZUG" -p json &
exec 3>"$FIFO_UEBERZUG"
trap cleanup EXIT
vifm "$@" 3>&-
vifmimg clear
fi fi
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

Loading…
Cancel
Save