Merge pull request #1006 from luukvbaal/preview-tui

Kill kitty icat in preview-tui
This commit is contained in:
Piña Colada 2021-05-14 07:52:54 +05:30 committed by GitHub
commit 2ca11a34e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 26 deletions

View file

@ -71,7 +71,7 @@ TMPDIR="${TMPDIR:-/tmp}"
startpreview() { startpreview() {
NUMPREVIEWTUI="$(($(find "$TMPDIR" -maxdepth 1 -name 'nnn-preview-tui-pagerpid*' 2>/dev/null | wc -l) + 1))" NUMPREVIEWTUI="$(($(find "$TMPDIR" -maxdepth 1 -name 'nnn-preview-tui-pagerpid*' 2>/dev/null | wc -l) + 1))"
PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NUMPREVIEWTUI" PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NUMPREVIEWTUI"
GIFPID="$TMPDIR/nnn-preview-tui-gifpid.$NUMPREVIEWTUI" IMGPID="$TMPDIR/nnn-preview-tui-gifpid.$NUMPREVIEWTUI"
CURSEL="$TMPDIR/nnn-preview-tui-selection.$NUMPREVIEWTUI" CURSEL="$TMPDIR/nnn-preview-tui-selection.$NUMPREVIEWTUI"
FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NUMPREVIEWTUI" FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NUMPREVIEWTUI"
@ -97,7 +97,7 @@ startpreview() {
tmux split-window -e "NNN_FIFO=$NNN_FIFO" -e "PREVIEW_MODE=1" -e "PAGER=$PAGER" \ tmux split-window -e "NNN_FIFO=$NNN_FIFO" -e "PREVIEW_MODE=1" -e "PAGER=$PAGER" \
-e "USE_SCOPE=$USE_SCOPE" -e "SPLIT=$SPLIT" -e "USE_PISTOL=$USE_PISTOL" \ -e "USE_SCOPE=$USE_SCOPE" -e "SPLIT=$SPLIT" -e "USE_PISTOL=$USE_PISTOL" \
-e "PAGERPID=$PAGERPID" -e "GIFPID=$GIFPID" -e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" \ -e "PAGERPID=$PAGERPID" -e "IMGPID=$IMGPID" -e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" \
-e "FIFO_UEBERZUG=$FIFO_UEBERZUG" -e "QLPATH=$QLPATH" -d"$SPLIT" "$0" "$1" -e "FIFO_UEBERZUG=$FIFO_UEBERZUG" -e "QLPATH=$QLPATH" -d"$SPLIT" "$0" "$1"
elif [ "$TERMINAL" = "kitty" ]; then elif [ "$TERMINAL" = "kitty" ]; then
# Setting the layout for the new window. It will be restored after the # Setting the layout for the new window. It will be restored after the
@ -112,12 +112,12 @@ startpreview() {
--env "PREVIEW_MODE=1" --env "PAGER=$PAGER" --env "TMPDIR=$TMPDIR" \ --env "PREVIEW_MODE=1" --env "PAGER=$PAGER" --env "TMPDIR=$TMPDIR" \
--env "USE_SCOPE=$USE_SCOPE" --env "SPLIT=$SPLIT" --env "TERMINAL=$TERMINAL"\ --env "USE_SCOPE=$USE_SCOPE" --env "SPLIT=$SPLIT" --env "TERMINAL=$TERMINAL"\
--env "USE_PISTOL=$USE_PISTOL" --env "PAGERPID=$PAGERPID" \ --env "USE_PISTOL=$USE_PISTOL" --env "PAGERPID=$PAGERPID" \
--env "GIFPID=$GIFPID" --env "FIFO_UEBERZUG=$FIFO_UEBERZUG" \ --env "IMGPID=$IMGPID" --env "FIFO_UEBERZUG=$FIFO_UEBERZUG" \
--env "CURSEL=$CURSEL" --location "${SPLIT}split" "$0" "$1" >/dev/null --env "CURSEL=$CURSEL" --location "${SPLIT}split" "$0" "$1" >/dev/null
elif [ -n "$2" ]; then elif [ -n "$2" ]; then
QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" >/dev/null & QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" >/dev/null &
else else
PAGERPID="$PAGERPID" GIFPID="$GIFPID" CURSEL="$CURSEL" PREVIEW_MODE=1 \ PAGERPID="$PAGERPID" IMGPID="$IMGPID" CURSEL="$CURSEL" PREVIEW_MODE=1 \
FIFO_UEBERZUG="$FIFO_UEBERZUG" $TERMINAL -e "$0" "$1" 2>/dev/null & FIFO_UEBERZUG="$FIFO_UEBERZUG" $TERMINAL -e "$0" "$1" 2>/dev/null &
fi fi
} }
@ -244,18 +244,18 @@ preview_file () {
image_preview() { image_preview() {
if [ "$TERMINAL" = "kitty" ]; then if [ "$TERMINAL" = "kitty" ]; then
# Kitty terminal users can use the native image preview method. # Kitty terminal users can use the native image preview method.
kitty +kitten icat --silent --place "$1"x"$2"@0x0 --transfer-mode=stream --stdin=no \ kitty +kitten icat --silent --place "$1"x"$2"@0x0 --transfer-mode=stream --stdin=no "$3" &
"$3" printf "%s" "$!" > "$IMGPID"
elif [ -n "$QLPATH" ] && stat "$3" >/dev/null 2>&1; then elif [ -n "$QLPATH" ] && stat "$3" >/dev/null 2>&1; then
f="$(wslpath -w "$3" 2>&1)" && "$QLPATH" "$f" & f="$(wslpath -w "$3" 2>&1)" && "$QLPATH" "$f" &
elif exists ueberzug; then elif exists ueberzug; then
ueberzug_layer "$1" "$2" "$3" ueberzug_layer "$1" "$2" "$3"
elif exists catimg; then elif exists catimg; then
catimg "$3" & catimg "$3" &
printf "%s" "$!" > "$GIFPID" printf "%s" "$!" > "$IMGPID"
elif exists viu; then elif exists viu; then
viu -t "$3" & viu -t "$3" &
printf "%s" "$!" > "$GIFPID" printf "%s" "$!" > "$IMGPID"
else else
fifo_pager print_bin_info "$3" fifo_pager print_bin_info "$3"
fi fi
@ -271,7 +271,7 @@ ueberzug_remove() {
ueberzug_refresh() { ueberzug_refresh() {
clear clear
kill "$(cat "$GIFPID" 2>/dev/null)" >/dev/null 2>&1 kill "$(cat "$IMGPID" 2>/dev/null)" >/dev/null 2>&1
pkill -P "$$" >/dev/null 2>&1 pkill -P "$$" >/dev/null 2>&1
pkill -f -n preview-tui-ext >/dev/null 2>&1 pkill -f -n preview-tui-ext >/dev/null 2>&1
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json & tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
@ -286,16 +286,16 @@ preview_fifo() {
# shellcheck disable=SC2002 # shellcheck disable=SC2002
cat "$NNN_FIFO" |\ cat "$NNN_FIFO" |\
while read -r selection; do while read -r selection; do
kill "$(cat "$GIFPID" 2>/dev/null)" >/dev/null 2>&1 kill "$(cat "$IMGPID" 2>/dev/null)" >/dev/null 2>&1
kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1 kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove [ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
preview_file "$selection" preview_file "$selection"
printf "%s" "$selection" > "$CURSEL" printf "%s" "$selection" > "$CURSEL"
done done
kill "$(cat "$GIFPID" 2>/dev/null)" >/dev/null 2>&1 kill "$(cat "$IMGPID" 2>/dev/null)" >/dev/null 2>&1
kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1 kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove [ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
rm "$PAGERPID" "$GIFPID" "$CURSEL" "$FIFO_UEBERZUG" >/dev/null 2>&1 rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" >/dev/null 2>&1
pkill -P "$$" >/dev/null 2>&1 pkill -P "$$" >/dev/null 2>&1
} }
@ -305,7 +305,7 @@ if [ "$PREVIEW_MODE" ]; then
trap 'ueberzug_refresh; rm "$FIFO_UEBERZUG"' WINCH trap 'ueberzug_refresh; rm "$FIFO_UEBERZUG"' WINCH
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json & tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
fi fi
trap 'rm "$PAGERPID" "$GIFPID" "$CURSEL" "$FIFO_UEBERZUG" 2>/dev/null' INT HUP EXIT trap 'rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" 2>/dev/null' INT HUP EXIT
preview_file "$PWD/$1" preview_file "$PWD/$1"
printf "%s" "$PWD/$1" > "$CURSEL" & printf "%s" "$PWD/$1" > "$CURSEL" &

View file

@ -87,7 +87,7 @@ NNN_PREVIEWHEIGHT="${NNN_PREVIEWHEIGHT:-1080}"
startpreview() { startpreview() {
NUMPREVIEWTUI="$(($(find "$TMPDIR" -maxdepth 1 -name 'nnn-preview-tui-pagerpid*' 2>/dev/null | wc -l) + 1))" NUMPREVIEWTUI="$(($(find "$TMPDIR" -maxdepth 1 -name 'nnn-preview-tui-pagerpid*' 2>/dev/null | wc -l) + 1))"
PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NUMPREVIEWTUI" PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NUMPREVIEWTUI"
GIFPID="$TMPDIR/nnn-preview-tui-gifpid.$NUMPREVIEWTUI" IMGPID="$TMPDIR/nnn-preview-tui-gifpid.$NUMPREVIEWTUI"
CURSEL="$TMPDIR/nnn-preview-tui-selection.$NUMPREVIEWTUI" CURSEL="$TMPDIR/nnn-preview-tui-selection.$NUMPREVIEWTUI"
FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NUMPREVIEWTUI" FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NUMPREVIEWTUI"
@ -113,7 +113,7 @@ startpreview() {
tmux split-window -e "NNN_FIFO=$NNN_FIFO" -e "PREVIEW_MODE=1" -e "PAGER=$PAGER" \ tmux split-window -e "NNN_FIFO=$NNN_FIFO" -e "PREVIEW_MODE=1" -e "PAGER=$PAGER" \
-e "USE_SCOPE=$USE_SCOPE" -e "SPLIT=$SPLIT" -e "USE_PISTOL=$USE_PISTOL" \ -e "USE_SCOPE=$USE_SCOPE" -e "SPLIT=$SPLIT" -e "USE_PISTOL=$USE_PISTOL" \
-e "PAGERPID=$PAGERPID" -e "GIFPID=$GIFPID" -e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" \ -e "PAGERPID=$PAGERPID" -e "IMGPID=$IMGPID" -e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" \
-e "ICONLOOKUP=$ICONLOOKUP" -e "NNN_PREVIEWDIR=$NNN_PREVIEWDIR" \ -e "ICONLOOKUP=$ICONLOOKUP" -e "NNN_PREVIEWDIR=$NNN_PREVIEWDIR" \
-e "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" -e "NNN_PREVIEWHEIGHT=$NNN_PREVIEWHEIGHT" \ -e "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" -e "NNN_PREVIEWHEIGHT=$NNN_PREVIEWHEIGHT" \
-e "FIFO_UEBERZUG=$FIFO_UEBERZUG" -e "QLPATH=$2" -d"$SPLIT" "$0" "$1" -e "FIFO_UEBERZUG=$FIFO_UEBERZUG" -e "QLPATH=$2" -d"$SPLIT" "$0" "$1"
@ -130,14 +130,14 @@ startpreview() {
--env "PREVIEW_MODE=1" --env "PAGER=$PAGER" --env "TMPDIR=$TMPDIR" \ --env "PREVIEW_MODE=1" --env "PAGER=$PAGER" --env "TMPDIR=$TMPDIR" \
--env "USE_SCOPE=$USE_SCOPE" --env "SPLIT=$SPLIT" --env "TERMINAL=$TERMINAL"\ --env "USE_SCOPE=$USE_SCOPE" --env "SPLIT=$SPLIT" --env "TERMINAL=$TERMINAL"\
--env "USE_PISTOL=$USE_PISTOL" --env "PAGERPID=$PAGERPID" \ --env "USE_PISTOL=$USE_PISTOL" --env "PAGERPID=$PAGERPID" \
--env "GIFPID=$GIFPID" --env "FIFO_UEBERZUG=$FIFO_UEBERZUG" \ --env "IMGPID=$IMGPID" --env "FIFO_UEBERZUG=$FIFO_UEBERZUG" \
--env "ICONLOOKUP=$ICONLOOKUP" --env "NNN_PREVIEWDIR=$NNN_PREVIEWDIR" \ --env "ICONLOOKUP=$ICONLOOKUP" --env "NNN_PREVIEWDIR=$NNN_PREVIEWDIR" \
--env "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" --env "NNN_PREVIEWHEIGHT=$NNN_PREVIEWHEIGHT" \ --env "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" --env "NNN_PREVIEWHEIGHT=$NNN_PREVIEWHEIGHT" \
--env "CURSEL=$CURSEL" --location "${SPLIT}split" "$0" "$1" >/dev/null --env "CURSEL=$CURSEL" --location "${SPLIT}split" "$0" "$1" >/dev/null
elif [ -n "$2" ]; then elif [ -n "$2" ]; then
QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" >/dev/null & QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" >/dev/null &
else else
PAGERPID="$PAGERPID" GIFPID="$GIFPID" CURSEL="$CURSEL" PREVIEW_MODE=1 \ PAGERPID="$PAGERPID" IMGPID="$IMGPID" CURSEL="$CURSEL" PREVIEW_MODE=1 \
FIFO_UEBERZUG="$FIFO_UEBERZUG" $TERMINAL -e "$0" "$1" 2>/dev/null & FIFO_UEBERZUG="$FIFO_UEBERZUG" $TERMINAL -e "$0" "$1" 2>/dev/null &
fi fi
} }
@ -331,7 +331,7 @@ generate_preview() {
sleep 0.1 sleep 0.1
done done
done & done &
printf "%s" "$!" > "$GIFPID" printf "%s" "$!" > "$IMGPID"
return return
else else
image_preview "$1" "$2" "$3" image_preview "$1" "$2" "$3"
@ -356,15 +356,16 @@ image_preview() {
clear clear
if [ "$TERMINAL" = "kitty" ]; then if [ "$TERMINAL" = "kitty" ]; then
# Kitty terminal users can use the native image preview method. # Kitty terminal users can use the native image preview method.
kitty +kitten icat --silent --place "$1"x"$2"@0x0 --transfer-mode=stream --stdin=no "$3" kitty +kitten icat --silent --place "$1"x"$2"@0x0 --transfer-mode=stream --stdin=no "$3" &
printf "%s" "$!" > "$IMGPID"
elif exists ueberzug; then elif exists ueberzug; then
ueberzug_layer "$1" "$2" "$3" ueberzug_layer "$1" "$2" "$3"
elif exists catimg; then elif exists catimg; then
catimg "$3" & catimg "$3" &
printf "%s" "$!" > "$GIFPID" printf "%s" "$!" > "$IMGPID"
elif exists viu; then elif exists viu; then
viu -t "$3" & viu -t "$3" &
printf "%s" "$!" > "$GIFPID" printf "%s" "$!" > "$IMGPID"
else else
fifo_pager print_bin_info "$3" fifo_pager print_bin_info "$3"
fi fi
@ -380,7 +381,7 @@ ueberzug_remove() {
ueberzug_refresh() { ueberzug_refresh() {
clear clear
kill "$(cat "$GIFPID" 2>/dev/null)" >/dev/null 2>&1 kill "$(cat "$IMGPID" 2>/dev/null)" >/dev/null 2>&1
pkill -P "$$" >/dev/null 2>&1 pkill -P "$$" >/dev/null 2>&1
pkill -f -n preview-tui-ext >/dev/null 2>&1 pkill -f -n preview-tui-ext >/dev/null 2>&1
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json & tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
@ -395,16 +396,16 @@ preview_fifo() {
# shellcheck disable=SC2002 # shellcheck disable=SC2002
cat "$NNN_FIFO" |\ cat "$NNN_FIFO" |\
while read -r selection; do while read -r selection; do
kill "$(cat "$GIFPID" 2>/dev/null)" >/dev/null 2>&1 kill "$(cat "$IMGPID" 2>/dev/null)" >/dev/null 2>&1
kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1 kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove [ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
preview_file "$selection" preview_file "$selection"
printf "%s" "$selection" > "$CURSEL" printf "%s" "$selection" > "$CURSEL"
done done
kill "$(cat "$GIFPID" 2>/dev/null)" >/dev/null 2>&1 kill "$(cat "$IMGPID" 2>/dev/null)" >/dev/null 2>&1
kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1 kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove [ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
rm "$PAGERPID" "$GIFPID" "$CURSEL" "$FIFO_UEBERZUG" >/dev/null 2>&1 rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" >/dev/null 2>&1
pkill -P "$$" >/dev/null 2>&1 pkill -P "$$" >/dev/null 2>&1
} }
@ -414,7 +415,7 @@ if [ "$PREVIEW_MODE" ]; then
trap 'ueberzug_refresh; rm "$FIFO_UEBERZUG"' WINCH trap 'ueberzug_refresh; rm "$FIFO_UEBERZUG"' WINCH
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json & tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
fi fi
trap 'rm "$PAGERPID" "$GIFPID" "$CURSEL" "$FIFO_UEBERZUG" 2>/dev/null' INT HUP EXIT trap 'rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" 2>/dev/null' INT HUP EXIT
preview_file "$PWD/$1" preview_file "$PWD/$1"
printf "%s" "$PWD/$1" > "$CURSEL" & printf "%s" "$PWD/$1" > "$CURSEL" &