# Dependencies:
# - Supports 4 independent methods to preview with:
# - tmux (>=3.0), or
-# - kitty with allow_remote_control on, or
+# - kitty with allow_remote_control and listen_on set in kitty.conf, or
# - QuickLook on WSL (https://github.com/QL-Win/QuickLook)
# - $TERMINAL set to a terminal (it's xterm by default).
# - less or $PAGER
if [ -e "${TMUX%%,*}" ] && tmux -V | grep -q '[ -][3456789]\.'; then
TERMINAL=tmux
- elif [ -n "$KITTY_WINDOW_ID" ] && kitty @ ls >/dev/null 2>&1; then
+ elif [ -n "$KITTY_LISTEN_ON" ]; then
TERMINAL=kitty
else
TERMINAL="${TERMINAL:-xterm}"
ueberzug_layer "$1" "$2" "$3"
elif exists catimg; then
catimg "$3" &
- echo "$!" > "$GIFPID"
+ printf "%s" "$!" > "$GIFPID"
elif exists viu; then
viu -t "$3" &
- echo "$!" > "$GIFPID"
+ printf "%s" "$!" > "$GIFPID"
else
fifo_pager print_bin_info "$3"
fi
pkill -f -n preview-tui-ext >/dev/null 2>&1
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
preview_file "$(cat "$CURSEL")"
- echo > "$NNN_FIFO"
+ printf "\n" > "$NNN_FIFO"
preview_fifo 2>/dev/null &
wait
}
kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
preview_file "$selection"
- echo "$selection" > "$CURSEL"
+ printf "%s" "$selection" > "$CURSEL"
done
[ "$TERMINAL" != "kitty" ] && exists ueberzug && rm "$FIFO_UEBERZUG"
rm "$PAGERPID" "$GIFPID" "$CURSEL" >/dev/null 2>&1
}
if [ "$PREVIEW_MODE" ]; then
- if [ ! -r "$NNN_FIFO" ]; then
- echo "No FIFO available! (\$NNN_FIFO='$NNN_FIFO')" >&2
- read -r
- exit 1
- fi
-
if [ "$TERMINAL" != "kitty" ] && exists ueberzug; then
mkfifo "$FIFO_UEBERZUG"
trap 'ueberzug_refresh; rm $FIFO_UEBERZUG' WINCH
preview_file "$1"
preview_fifo 2>/dev/null &
wait
+else
+ if [ ! -r "$NNN_FIFO" ]; then
+ clear
+ printf "No FIFO available! (\$NNN_FIFO='%s')\nPlease read the documentation" "$NNN_FIFO"
+ read -r _
+ elif [ "$KITTY_WINDOW_ID" ] && [ -z "$KITTY_LISTEN_ON" ]; then
+ # The escape codes used to control kitty splits cause problems when run from a background process.
+ # Use --listen-on flag or listen_on config variable to avoid(https://sw.kovidgoyal.net/kitty/conf.html)
+ clear
+ printf "\$KITTY_LISTEN_ON not set!\nPlease add listen_on to your kitty.conf or start with the --listen-on flag."
+ read -r _
+ else
+ togglepreview "$1" &
+ fi
fi
-
-togglepreview "$1" &
# Dependencies:
# - Supports 4 independent methods to preview with:
# - tmux (>=3.0), or
-# - kitty with allow_remote_control on, or
+# - kitty with allow_remote_control and listen_on set in kitty.conf, or
# - QuickLook on WSL (https://github.com/QL-Win/QuickLook)
# - $TERMINAL set to a terminal (it's xterm by default).
# - less or $PAGER
#
# Shell: POSIX compliant
# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero, Luuk van Baal
+
SPLIT="$SPLIT" # you can set a permanent split here
TERMINAL="$TERMINAL" # same goes for the terminal
USE_SCOPE="${USE_SCOPE:-0}"
if [ -e "${TMUX%%,*}" ] && tmux -V | grep -q '[ -][3456789]\.'; then
TERMINAL=tmux
- elif [ -n "$KITTY_WINDOW_ID" ] && kitty @ ls >/dev/null 2>&1; then
+ elif [ -n "$KITTY_LISTEN_ON" ]; then
TERMINAL=kitty
else
TERMINAL="${TERMINAL:-xterm}"
mkfifo "$tmpfifopath" || return
$PAGER < "$tmpfifopath" &
- echo "$!" > "$PAGERPID"
+ printf "%s" "$!" > "$PAGERPID"
(
exec > "$tmpfifopath"
done
[ "$LOOP_GIFS" -eq 0 ] && return
done &
- echo "$!" > "$GIFPID"
+ printf "%s" "$!" > "$GIFPID"
return
else
image_preview "$1" "$2" "$3"
fi ;;
image) convert "$3" -flatten -resize "$NNN_PREVIEWWIDTH"x"$NNN_PREVIEWHEIGHT"\> "$NNN_PREVIEWDIR/$3.jpg" ;;
office) libreoffice --convert-to jpg "$3" --outdir "$NNN_PREVIEWDIR/${3%/*}" > /dev/null 2>&1
- filename="$(echo "${3##*/}" | cut -d. -f1)"
+ filename="$(printf "%s" "${3##*/}" | cut -d. -f1)"
mv "$NNN_PREVIEWDIR/${3%/*}/$filename.jpg" "$NNN_PREVIEWDIR/$3.jpg" ;;
pdf) pdftoppm -jpeg -f 1 -singlefile "$3" "$NNN_PREVIEWDIR/$3" >/dev/null 2>&1 ;;
video) ffmpegthumbnailer -m -s0 -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" >/dev/null 2>&1 || rm "$NNN_PREVIEWDIR/$3.jpg" ;;
ueberzug_layer "$1" "$2" "$3"
elif exists catimg; then
catimg "$3" &
- echo "$!" > "$GIFPID"
+ printf "%s" "$!" > "$GIFPID"
elif exists viu; then
viu -t "$3" &
- echo "$!" > "$GIFPID"
+ printf "%s" "$!" > "$GIFPID"
else
fifo_pager print_bin_info "$3"
fi
pkill -f -n preview-tui-ext >/dev/null 2>&1
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
preview_file "$(cat "$CURSEL")"
- echo > "$NNN_FIFO"
+ printf "\n" > "$NNN_FIFO"
preview_fifo 2>/dev/null &
wait
}
kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
preview_file "$selection"
- echo "$selection" > "$CURSEL"
+ printf "%s" "$selection" > "$CURSEL"
done
[ "$TERMINAL" != "kitty" ] && exists ueberzug && rm "$FIFO_UEBERZUG"
rm "$PAGERPID" "$GIFPID" "$CURSEL" >/dev/null 2>&1
}
if [ "$PREVIEW_MODE" ]; then
- if [ ! -r "$NNN_FIFO" ]; then
- echo "No FIFO available! (\$NNN_FIFO='$NNN_FIFO')" >&2
- read -r
- exit 1
- fi
-
if [ "$TERMINAL" != "kitty" ] && exists ueberzug; then
mkfifo "$FIFO_UEBERZUG"
trap 'ueberzug_refresh; rm $FIFO_UEBERZUG' WINCH
preview_file "$1"
preview_fifo 2>/dev/null &
wait
+else
+ if [ ! -r "$NNN_FIFO" ]; then
+ clear
+ printf "No FIFO available! (\$NNN_FIFO='%s')\nPlease read the documentation" "$NNN_FIFO"
+ read -r _
+ elif [ "$KITTY_WINDOW_ID" ] && [ -z "$KITTY_LISTEN_ON" ]; then
+ # The escape codes used to control kitty splits cause problems when run from a background process.
+ # Use --listen-on flag or listen_on config variable to avoid(https://sw.kovidgoyal.net/kitty/conf.html)
+ clear
+ printf "\$KITTY_LISTEN_ON not set!\nPlease add listen_on to your kitty.conf or start with the --listen-on flag."
+ read -r _
+ else
+ togglepreview "$1" &
+ fi
fi
-
-togglepreview "$1" &