mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Preview-tui single previewpid file
This commit is contained in:
parent
4637a5a84d
commit
c9c0be32a8
|
@ -84,8 +84,7 @@ NNN_PREVIEWWIDTH="${NNN_PREVIEWWIDTH:-1920}"
|
||||||
NNN_PREVIEWHEIGHT="${NNN_PREVIEWHEIGHT:-1080}"
|
NNN_PREVIEWHEIGHT="${NNN_PREVIEWHEIGHT:-1080}"
|
||||||
NNN_PARENT="${NNN_FIFO#*.}"
|
NNN_PARENT="${NNN_FIFO#*.}"
|
||||||
FIFOPID="$TMPDIR/nnn-preview-tui-fifopid.$NNN_PARENT"
|
FIFOPID="$TMPDIR/nnn-preview-tui-fifopid.$NNN_PARENT"
|
||||||
PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NNN_PARENT"
|
PREVIEWPID="$TMPDIR/nnn-preview-tui-pagerpid.$NNN_PARENT"
|
||||||
IMGPID="$TMPDIR/nnn-preview-tui-imgpid.$NNN_PARENT"
|
|
||||||
CURSEL="$TMPDIR/nnn-preview-tui-selection.$NNN_PARENT"
|
CURSEL="$TMPDIR/nnn-preview-tui-selection.$NNN_PARENT"
|
||||||
FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NNN_PARENT"
|
FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NNN_PARENT"
|
||||||
|
|
||||||
|
@ -109,12 +108,12 @@ start_preview() {
|
||||||
case "$TERMINAL" in
|
case "$TERMINAL" in
|
||||||
tmux) # tmux splits are inverted
|
tmux) # tmux splits are inverted
|
||||||
if [ "$SPLIT" = "v" ]; then DSPLIT="h"; else DSPLIT="v"; fi
|
if [ "$SPLIT" = "v" ]; then DSPLIT="h"; else DSPLIT="v"; fi
|
||||||
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 "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" -e "FIFOPID=$FIFOPID" \
|
||||||
|
-e "BAT_STYLE=$BAT_STYLE" -e "PREVIEWPID=$PREVIEWPID" -e "PAGER=$PAGER" \
|
||||||
|
-e "ICONLOOKUP=$ICONLOOKUP" -e "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" \
|
||||||
-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 "BAT_STYLE=$BAT_STYLE" -e "PAGERPID=$PAGERPID" -e "FIFOPID=$FIFOPID" \
|
-e "NNN_PREVIEWDIR=$NNN_PREVIEWDIR" -e "NNN_PREVIEWHEIGHT=$NNN_PREVIEWHEIGHT" \
|
||||||
-e "IMGPID=$IMGPID" -e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" \
|
|
||||||
-e "ICONLOOKUP=$ICONLOOKUP" -e "NNN_PREVIEWDIR=$NNN_PREVIEWDIR" \
|
|
||||||
-e "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" -e "NNN_PREVIEWHEIGHT=$NNN_PREVIEWHEIGHT" \
|
|
||||||
-e "FIFO_UEBERZUG=$FIFO_UEBERZUG" -e "QLPATH=$2" -d"$DSPLIT" "$0" "$1" ;;
|
-e "FIFO_UEBERZUG=$FIFO_UEBERZUG" -e "QLPATH=$2" -d"$DSPLIT" "$0" "$1" ;;
|
||||||
kitty) # Setting the layout for the new window. It will be restored after the script ends.
|
kitty) # Setting the layout for the new window. It will be restored after the script ends.
|
||||||
kitty @ goto-layout splits
|
kitty @ goto-layout splits
|
||||||
|
@ -124,15 +123,15 @@ start_preview() {
|
||||||
--cwd "$PWD" --env "PATH=$PATH" --env "NNN_FIFO=$NNN_FIFO" \
|
--cwd "$PWD" --env "PATH=$PATH" --env "NNN_FIFO=$NNN_FIFO" \
|
||||||
--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 "PREVIEWPID=$PREVIEWPID" --env "FIFO_UEBERZUG=$FIFO_UEBERZUG" \
|
||||||
|
--env "ICONLOOKUP=$ICONLOOKUP" --env "NNN_PREVIEWHEIGHT=$NNN_PREVIEWHEIGHT" \
|
||||||
|
--env "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" --env "NNN_PREVIEWDIR=$NNN_PREVIEWDIR" \
|
||||||
--env "USE_PISTOL=$USE_PISTOL" --env "BAT_STYLE=$BAT_STYLE" --env "FIFOPID=$FIFOPID" \
|
--env "USE_PISTOL=$USE_PISTOL" --env "BAT_STYLE=$BAT_STYLE" --env "FIFOPID=$FIFOPID" \
|
||||||
--env "PAGERPID=$PAGERPID" --env "IMGPID=$IMGPID" --env "FIFO_UEBERZUG=$FIFO_UEBERZUG" \
|
|
||||||
--env "ICONLOOKUP=$ICONLOOKUP" --env "NNN_PREVIEWDIR=$NNN_PREVIEWDIR" \
|
|
||||||
--env "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" --env "NNN_PREVIEWHEIGHT=$NNN_PREVIEWHEIGHT" \
|
|
||||||
--env "CURSEL=$CURSEL" --location "${SPLIT}split" "$0" "$1" ;;
|
--env "CURSEL=$CURSEL" --location "${SPLIT}split" "$0" "$1" ;;
|
||||||
*) if [ -n "$2" ]; then
|
*) if [ -n "$2" ]; then
|
||||||
QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" &
|
QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" &
|
||||||
else
|
else
|
||||||
PAGERPID="$PAGERPID" IMGPID="$IMGPID" CURSEL="$CURSEL" PREVIEW_MODE=1 \
|
PREVIEWPID="$PREVIEWPID" CURSEL="$CURSEL" PREVIEW_MODE=1 \
|
||||||
FIFOPID="$FIFOPID" FIFO_UEBERZUG="$FIFO_UEBERZUG" $TERMINAL -e "$0" "$1" &
|
FIFOPID="$FIFOPID" FIFO_UEBERZUG="$FIFO_UEBERZUG" $TERMINAL -e "$0" "$1" &
|
||||||
fi ;;
|
fi ;;
|
||||||
esac
|
esac
|
||||||
|
@ -145,8 +144,7 @@ toggle_preview() {
|
||||||
QLPATH="Bridge.exe"
|
QLPATH="Bridge.exe"
|
||||||
fi
|
fi
|
||||||
if kill "$(cat "$FIFOPID")"; then
|
if kill "$(cat "$FIFOPID")"; then
|
||||||
kill "$(cat "$IMGPID")"
|
kill "$(cat "$PREVIEWPID")"
|
||||||
kill "$(cat "$PAGERPID")"
|
|
||||||
pkill -f "tail --follow $FIFO_UEBERZUG"
|
pkill -f "tail --follow $FIFO_UEBERZUG"
|
||||||
if [ -n "$QLPATH" ] && stat "$1"; then
|
if [ -n "$QLPATH" ] && stat "$1"; then
|
||||||
f="$(wslpath -w "$1")" && "$QLPATH" "$f" &
|
f="$(wslpath -w "$1")" && "$QLPATH" "$f" &
|
||||||
|
@ -169,7 +167,7 @@ fifo_pager() {
|
||||||
mkfifo "$tmpfifopath" || return
|
mkfifo "$tmpfifopath" || return
|
||||||
|
|
||||||
$PAGER < "$tmpfifopath" &
|
$PAGER < "$tmpfifopath" &
|
||||||
printf "%s" "$!" > "$PAGERPID"
|
printf "%s" "$!" > "$PREVIEWPID"
|
||||||
|
|
||||||
(
|
(
|
||||||
exec > "$tmpfifopath"
|
exec > "$tmpfifopath"
|
||||||
|
@ -324,7 +322,7 @@ generate_preview() {
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
done
|
done
|
||||||
done &
|
done &
|
||||||
printf "%s" "$!" > "$IMGPID"
|
printf "%s" "$!" > "$PREVIEWPID"
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
exec >/dev/tty
|
exec >/dev/tty
|
||||||
|
@ -360,7 +358,7 @@ image_preview() {
|
||||||
else
|
else
|
||||||
fifo_pager print_bin_info "$3" && return
|
fifo_pager print_bin_info "$3" && return
|
||||||
fi
|
fi
|
||||||
printf "%s" "$!" > "$IMGPID"
|
printf "%s" "$!" > "$PREVIEWPID"
|
||||||
} 2>/dev/null
|
} 2>/dev/null
|
||||||
|
|
||||||
ueberzug_layer() {
|
ueberzug_layer() {
|
||||||
|
@ -373,8 +371,7 @@ ueberzug_remove() {
|
||||||
|
|
||||||
winch_handler() {
|
winch_handler() {
|
||||||
clear
|
clear
|
||||||
kill "$(cat "$IMGPID")"
|
kill "$(cat "$PREVIEWPID")"
|
||||||
kill "$(cat "$PAGERPID")"
|
|
||||||
if [ -p "$FIFO_UEBERZUG" ]; then
|
if [ -p "$FIFO_UEBERZUG" ]; then
|
||||||
pkill -f "tail --follow $FIFO_UEBERZUG"
|
pkill -f "tail --follow $FIFO_UEBERZUG"
|
||||||
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
||||||
|
@ -388,8 +385,7 @@ winch_handler() {
|
||||||
preview_fifo() {
|
preview_fifo() {
|
||||||
while read -r selection; do
|
while read -r selection; do
|
||||||
if [ -n "$selection" ]; then
|
if [ -n "$selection" ]; then
|
||||||
kill "$(cat "$IMGPID")"
|
kill "$(cat "$PREVIEWPID")"
|
||||||
kill "$(cat "$PAGERPID")"
|
|
||||||
[ -p "$FIFO_UEBERZUG" ] && ueberzug_remove
|
[ -p "$FIFO_UEBERZUG" ] && ueberzug_remove
|
||||||
preview_file "$selection"
|
preview_file "$selection"
|
||||||
printf "%s" "$selection" > "$CURSEL"
|
printf "%s" "$selection" > "$CURSEL"
|
||||||
|
@ -409,7 +405,7 @@ if [ "$PREVIEW_MODE" ]; then
|
||||||
printf "%s" "$!" > "$FIFOPID"
|
printf "%s" "$!" > "$FIFOPID"
|
||||||
printf "%s" "$PWD/$1" > "$CURSEL"
|
printf "%s" "$PWD/$1" > "$CURSEL"
|
||||||
trap 'winch_handler; wait' WINCH
|
trap 'winch_handler; wait' WINCH
|
||||||
trap 'rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" "$FIFOPID" 2>/dev/null' INT HUP EXIT
|
trap 'rm "$PREVIEWPID" "$CURSEL" "$FIFO_UEBERZUG" "$FIFOPID" 2>/dev/null' INT HUP EXIT
|
||||||
wait "$!" 2>/dev/null
|
wait "$!" 2>/dev/null
|
||||||
else
|
else
|
||||||
if [ ! -r "$NNN_FIFO" ]; then
|
if [ ! -r "$NNN_FIFO" ]; then
|
||||||
|
|
Loading…
Reference in a new issue