mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
preview-tui: error to foreground (#970)
* preview-tui: error to foreground * preview-tui: test KITTY_LISTEN_ON
This commit is contained in:
parent
b97e2d02ea
commit
d998943119
|
@ -8,7 +8,7 @@
|
|||
# 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
|
||||
|
@ -79,7 +79,7 @@ startpreview() {
|
|||
|
||||
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}"
|
||||
|
@ -240,10 +240,10 @@ image_preview() {
|
|||
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
|
||||
|
@ -264,7 +264,7 @@ ueberzug_refresh() {
|
|||
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
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ preview_fifo() {
|
|||
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
|
||||
|
@ -286,12 +286,6 @@ preview_fifo() {
|
|||
}
|
||||
|
||||
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
|
||||
|
@ -302,6 +296,18 @@ if [ "$PREVIEW_MODE" ]; then
|
|||
preview_file "$1"
|
||||
preview_fifo 2>/dev/null &
|
||||
wait
|
||||
fi
|
||||
|
||||
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
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
# 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
|
||||
|
@ -71,6 +71,7 @@
|
|||
#
|
||||
# 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}"
|
||||
|
@ -94,7 +95,7 @@ startpreview() {
|
|||
|
||||
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}"
|
||||
|
@ -169,7 +170,7 @@ fifo_pager() {
|
|||
mkfifo "$tmpfifopath" || return
|
||||
|
||||
$PAGER < "$tmpfifopath" &
|
||||
echo "$!" > "$PAGERPID"
|
||||
printf "%s" "$!" > "$PAGERPID"
|
||||
|
||||
(
|
||||
exec > "$tmpfifopath"
|
||||
|
@ -316,7 +317,7 @@ generate_preview() {
|
|||
done
|
||||
[ "$LOOP_GIFS" -eq 0 ] && return
|
||||
done &
|
||||
echo "$!" > "$GIFPID"
|
||||
printf "%s" "$!" > "$GIFPID"
|
||||
return
|
||||
else
|
||||
image_preview "$1" "$2" "$3"
|
||||
|
@ -324,7 +325,7 @@ generate_preview() {
|
|||
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" ;;
|
||||
|
@ -346,10 +347,10 @@ image_preview() {
|
|||
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
|
||||
|
@ -370,7 +371,7 @@ ueberzug_refresh() {
|
|||
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
|
||||
}
|
||||
|
@ -384,7 +385,7 @@ preview_fifo() {
|
|||
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
|
||||
|
@ -392,12 +393,6 @@ preview_fifo() {
|
|||
}
|
||||
|
||||
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
|
||||
|
@ -408,6 +403,18 @@ if [ "$PREVIEW_MODE" ]; then
|
|||
preview_file "$1"
|
||||
preview_fifo 2>/dev/null &
|
||||
wait
|
||||
fi
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue