mirror of
https://github.com/jarun/nnn.git
synced 2024-09-11 04:55:25 +03:00
preview-tui: tmux sixel support for img, gif & vid preview
This commit is contained in:
parent
f8f6d6a482
commit
9ff81ca1f9
@ -40,6 +40,11 @@
|
||||
# - optional: pistol file viewer (https://github.com/doronbehar/pistol).
|
||||
# 1. install pistol
|
||||
# 2. set/export $NNN_PISTOL as 1
|
||||
# - optional: sixel
|
||||
# - terminal with sixel support. ex. foot, wezterm, iterm2, macterm, mintty, etc. (check https://www.arewesixelyet.com/)
|
||||
# - tmux with sixel support (should be compiled with `./configure --enable-sixel`)
|
||||
# dependencies: mpv, img2sixel
|
||||
#
|
||||
#
|
||||
# Usage:
|
||||
# You need to set a NNN_FIFO path and a key for the plugin with NNN_PLUG,
|
||||
@ -162,7 +167,7 @@ start_preview() {
|
||||
tmux) # tmux splits are inverted
|
||||
ENVVARS=("${ENVVARS[@]/#/-e}")
|
||||
if [ "$NNN_SPLIT" = "v" ]; then split="h"; else split="v"; fi
|
||||
tmux split-window "${ENVVARS[@]}" -d"$split" -p"$NNN_SPLITSIZE" "$0" "$1" ;;
|
||||
tmux split-window -l"$NNN_SPLITSIZE"% "${ENVVARS[@]}" -d"$split" -p"$NNN_SPLITSIZE" "$0" "$1" ;;
|
||||
kitty) # Setting the layout for the new window. It will be restored after the script ends.
|
||||
ENVVARS=("${ENVVARS[@]/#/--env=}")
|
||||
kitty @ goto-layout splits
|
||||
@ -389,6 +394,9 @@ generate_preview() {
|
||||
done &
|
||||
printf "%s" "$!" > "$PREVIEWPID"
|
||||
return
|
||||
elif exists mpv; then
|
||||
video_preview "$1" "$2" "$3" 1
|
||||
return
|
||||
else
|
||||
image_preview "$1" "$2" "$3"
|
||||
return
|
||||
@ -403,7 +411,7 @@ generate_preview() {
|
||||
mv "$NNN_PREVIEWDIR/${3%/*}/$filename.jpg" "$NNN_PREVIEWDIR/$3.jpg" ;;
|
||||
pdf) pdftoppm -jpeg -f 1 -singlefile "$3" "$NNN_PREVIEWDIR/$3" ;;
|
||||
djvu) ddjvu -format=ppm -page=1 "$3" "$NNN_PREVIEWDIR/$3.jpg" ;;
|
||||
video) ffmpegthumbnailer -m -s0 -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" || rm "$NNN_PREVIEWDIR/$3.jpg" ;;
|
||||
video) video_preview "$1" "$2" "$3" && return ;;
|
||||
esac
|
||||
fi
|
||||
if [ -f "$NNN_PREVIEWDIR/$3.jpg" ]; then
|
||||
@ -428,12 +436,29 @@ image_preview() {
|
||||
viu -t "$3" &
|
||||
elif exists chafa && { [ -z "$NNN_PREVIEWIMGPROG" ] || [ "$NNN_PREVIEWIMGPROG" = "chafa" ] ;}; then
|
||||
chafa "$3" &
|
||||
elif exists img2sixel && { [ -z "$NNN_PREVIEWIMGPROG" ] || [ "$NNN_PREVIEWIMGPROG" = "img2sixel" ] ;}; then
|
||||
img2sixel -p16 -g "$3" &
|
||||
else
|
||||
fifo_pager print_bin_info "$3" && return
|
||||
fi
|
||||
printf "%s" "$!" > "$PREVIEWPID"
|
||||
}
|
||||
|
||||
video_preview() {
|
||||
clear
|
||||
exec >/dev/tty
|
||||
if type mpv >/dev/null 2>&1 ; then
|
||||
if [ "$4" -eq 1 ]; then # not gif
|
||||
mpv --no-config --really-quiet --vo=sixel --profile=sw-fast --loop-file --mute=yes --start="10%" --length=4 "$3" &
|
||||
else
|
||||
mpv --no-config --really-quiet --vo=sixel --profile=sw-fast --loop-file --mute=yes "$3" &
|
||||
fi
|
||||
else
|
||||
ffmpegthumbnailer -m -s0 -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" || rm "$NNN_PREVIEWDIR/$3.jpg" &
|
||||
fi
|
||||
printf "%s" "$!" > "$PREVIEWPID"
|
||||
}
|
||||
|
||||
ueberzug_layer() {
|
||||
[ -f "$POSOFFSET" ] && read -r x y < "$POSOFFSET"
|
||||
printf '{"action": "add", "identifier": "nnn_ueberzug", "x": %d, "y": %d, "width": "%d", "height": "%d", "scaler": "fit_contain", "path": "%s"}\n'\
|
||||
|
Loading…
Reference in New Issue
Block a user