mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Merge pull request #1013 from luukvbaal/preview-tui
Preview-tui cleanup
This commit is contained in:
commit
a95ed82f60
|
@ -59,20 +59,21 @@
|
||||||
# Shell: POSIX compliant
|
# Shell: POSIX compliant
|
||||||
# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero, Luuk van Baal
|
# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero, Luuk van Baal
|
||||||
|
|
||||||
SPLIT="$SPLIT" # you can set a permanent split here
|
#SPLIT="$SPLIT" # you can set a permanent split here
|
||||||
TERMINAL="$TERMINAL" # same goes for the terminal
|
#TERMINAL="$TERMINAL" # same goes for the terminal
|
||||||
USE_SCOPE="${USE_SCOPE:-0}"
|
USE_SCOPE="${USE_SCOPE:-0}"
|
||||||
USE_PISTOL="${USE_PISTOL:-0}"
|
USE_PISTOL="${USE_PISTOL:-0}"
|
||||||
PAGER="${PAGER:-less -P?n -R}"
|
PAGER="${PAGER:-less -P?n -R}"
|
||||||
TMPDIR="${TMPDIR:-/tmp}"
|
TMPDIR="${TMPDIR:-/tmp}"
|
||||||
|
BAT_STYLE="${BAT_STYLE:-numbers}"
|
||||||
|
NNN_PARENT="${NNN_FIFO#*.}"
|
||||||
|
FIFOPID="$TMPDIR/nnn-preview-tui-fifopid.$NNN_PARENT"
|
||||||
|
PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NNN_PARENT"
|
||||||
|
IMGPID="$TMPDIR/nnn-preview-tui-imgpid.$NNN_PARENT"
|
||||||
|
CURSEL="$TMPDIR/nnn-preview-tui-selection.$NNN_PARENT"
|
||||||
|
FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NNN_PARENT"
|
||||||
|
|
||||||
startpreview() {
|
start_preview() {
|
||||||
NUMPREVIEWTUI="$(($(find "$TMPDIR" -maxdepth 1 -name 'nnn-preview-tui-pagerpid*' 2>/dev/null | wc -l) + 1))"
|
|
||||||
PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NUMPREVIEWTUI"
|
|
||||||
IMGPID="$TMPDIR/nnn-preview-tui-gifpid.$NUMPREVIEWTUI"
|
|
||||||
CURSEL="$TMPDIR/nnn-preview-tui-selection.$NUMPREVIEWTUI"
|
|
||||||
FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NUMPREVIEWTUI"
|
|
||||||
|
|
||||||
[ "$PAGER" = "most" ] && PAGER="less -R"
|
[ "$PAGER" = "most" ] && PAGER="less -R"
|
||||||
|
|
||||||
if [ -e "${TMUX%%,*}" ] && tmux -V | grep -q '[ -][3456789]\.'; then
|
if [ -e "${TMUX%%,*}" ] && tmux -V | grep -q '[ -][3456789]\.'; then
|
||||||
|
@ -89,55 +90,51 @@ startpreview() {
|
||||||
SPLIT='v'
|
SPLIT='v'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$TERMINAL" = "tmux" ]; then
|
case "$TERMINAL" in
|
||||||
# tmux splits are inverted
|
tmux) # tmux splits are inverted
|
||||||
if [ "$SPLIT" = "v" ]; then SPLIT="h"; else SPLIT="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 "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 "BAT_STYLE=${BAT_STYLE:-numbers}" -e "PAGERPID=$PAGERPID" \
|
-e "BAT_STYLE=$BAT_STYLE" -e "PAGERPID=$PAGERPID" -e "FIFOPID=$FIFOPID" \
|
||||||
-e "IMGPID=$IMGPID" -e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" \
|
-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"$DSPLIT" "$0" "$1" ;;
|
||||||
elif [ "$TERMINAL" = "kitty" ]; then
|
kitty) # Setting the layout for the new window. It will be restored after the script ends.
|
||||||
# Setting the layout for the new window. It will be restored after the
|
kitty @ goto-layout splits
|
||||||
# script ends.
|
# Trying to use kitty's integrated window management as the split window. All
|
||||||
kitty @ goto-layout splits >/dev/null
|
# environmental variables that will be used in the new window must be explicitly passed.
|
||||||
|
|
||||||
# Trying to use kitty's integrated window management as the split window.
|
|
||||||
# All environmental variables that will be used in the new window must
|
|
||||||
# be explicitly passed.
|
|
||||||
kitty @ launch --no-response --title "nnn preview" --keep-focus \
|
kitty @ launch --no-response --title "nnn preview" --keep-focus \
|
||||||
--cwd "$PWD" --env "PATH=$PATH" --env "NNN_FIFO=$NNN_FIFO" \
|
--cwd "$PWD" --env "PATH=$PATH" --env "NNN_FIFO=$NNN_FIFO" --env "FIFOPID=$FIFOPID" \
|
||||||
--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 "BAT_STYLE=${BAT_STYLE:-numbers}" \
|
--env "USE_PISTOL=$USE_PISTOL" --env "BAT_STYLE=${BAT_STYLE:-numbers}" \
|
||||||
--env "PAGERPID=$PAGERPID" --env "IMGPID=$IMGPID" --env "FIFO_UEBERZUG=$FIFO_UEBERZUG" \
|
--env "PAGERPID=$PAGERPID" --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" ;;
|
||||||
elif [ -n "$2" ]; then
|
*) if [ -n "$2" ]; then
|
||||||
QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" >/dev/null &
|
QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" &
|
||||||
else
|
else
|
||||||
PAGERPID="$PAGERPID" IMGPID="$IMGPID" 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 &
|
FIFOPID="$FIFOPID" FIFO_UEBERZUG="$FIFO_UEBERZUG" $TERMINAL -e "$0" "$1" &
|
||||||
fi
|
fi ;;
|
||||||
}
|
esac
|
||||||
|
} >/dev/null 2>&1
|
||||||
|
|
||||||
togglepreview() {
|
toggle_preview() {
|
||||||
if exists QuickLook.exe; then
|
if exists QuickLook.exe; then
|
||||||
QLPATH="QuickLook.exe"
|
QLPATH="QuickLook.exe"
|
||||||
elif exists Bridge.exe; then
|
elif exists Bridge.exe; then
|
||||||
QLPATH="Bridge.exe"
|
QLPATH="Bridge.exe"
|
||||||
fi
|
fi
|
||||||
if pkill -fx "cat $NNN_FIFO" >/dev/null; then
|
if pkill -P "$(cat "$FIFOPID")"; then
|
||||||
if [ -n "$QLPATH" ] && stat "$1" >/dev/null 2>&1; then
|
if [ -n "$QLPATH" ] && stat "$1"; then
|
||||||
f="$(wslpath -w "$1" 2>&1)" && "$QLPATH" "$f" &
|
f="$(wslpath -w "$1")" && "$QLPATH" "$f" &
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
startpreview "$1" "$QLPATH"
|
start_preview "$1" "$QLPATH"
|
||||||
fi
|
fi
|
||||||
}
|
} >/dev/null 2>&1
|
||||||
|
|
||||||
exists() {
|
exists() {
|
||||||
type "$1" >/dev/null 2>&1
|
type "$1" >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
fifo_pager() {
|
fifo_pager() {
|
||||||
|
@ -156,7 +153,7 @@ fifo_pager() {
|
||||||
if [ "$cmd" = "pager" ]; then
|
if [ "$cmd" = "pager" ]; then
|
||||||
if exists bat; then
|
if exists bat; then
|
||||||
bat --terminal-width="$(tput cols)" --decorations=always --color=always \
|
bat --terminal-width="$(tput cols)" --decorations=always --color=always \
|
||||||
--paging=never --style="${BAT_STYLE:-numbers}" "$@" 2>/dev/null &
|
--paging=never --style="$BAT_STYLE" "$@" &
|
||||||
else
|
else
|
||||||
$PAGER "$@" &
|
$PAGER "$@" &
|
||||||
fi
|
fi
|
||||||
|
@ -166,17 +163,17 @@ fifo_pager() {
|
||||||
)
|
)
|
||||||
|
|
||||||
rm "$tmpfifopath"
|
rm "$tmpfifopath"
|
||||||
}
|
} 2>/dev/null
|
||||||
|
|
||||||
# Binary file: show file info inside the pager
|
# Binary file: show file info inside the pager
|
||||||
print_bin_info() {
|
print_bin_info() {
|
||||||
printf -- "-------- \033[1;31mBinary file\033[0m --------\n"
|
printf -- "-------- \033[1;31mBinary file\033[0m --------\n"
|
||||||
if exists mediainfo; then
|
if exists mediainfo; then
|
||||||
mediainfo "$1" 2>/dev/null
|
mediainfo "$1"
|
||||||
else
|
else
|
||||||
file -b "$1"
|
file -b "$1"
|
||||||
fi
|
fi
|
||||||
}
|
} 2>/dev/null
|
||||||
|
|
||||||
handle_mime() {
|
handle_mime() {
|
||||||
case "$2" in
|
case "$2" in
|
||||||
|
@ -213,25 +210,21 @@ preview_file () {
|
||||||
|
|
||||||
# Trying to use scope.sh if it's available.
|
# Trying to use scope.sh if it's available.
|
||||||
if [ "$USE_SCOPE" -ne 0 ] && exists scope.sh; then
|
if [ "$USE_SCOPE" -ne 0 ] && exists scope.sh; then
|
||||||
fifo_pager scope.sh "$1" "$cols" "$lines" "$(mktemp -d)" \
|
fifo_pager scope.sh "$1" "$cols" "$lines" "$(mktemp -d)" "True"
|
||||||
"True" 2>/dev/null
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use QuickLook if it's available.
|
# Use QuickLook if it's available.
|
||||||
if [ -n "$QUICKLOOK" ]; then
|
if [ -n "$QUICKLOOK" ]; then
|
||||||
stat "$1" >/dev/null 2>&1 && f="$(wslpath -w "$1" 2>&1)" && "$QLPATH" "$f" &
|
stat "$1" && f="$(wslpath -w "$1")" && "$QLPATH" "$f" &
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Detecting the exact type of the file: the encoding, mime type, and
|
# Detecting the exact type of the file: the encoding, mime type, and extension in lowercase.
|
||||||
# extension in lowercase.
|
|
||||||
encoding="$(file -bL --mime-encoding -- "$1")"
|
encoding="$(file -bL --mime-encoding -- "$1")"
|
||||||
mimetype="$(file -bL --mime-type -- "$1")"
|
mimetype="$(file -bL --mime-type -- "$1")"
|
||||||
ext="${1##*.}"
|
ext="${1##*.}"
|
||||||
if [ -n "$ext" ]; then
|
[ -n "$ext" ] && ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
|
||||||
ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
fi
|
|
||||||
lines=$(tput lines)
|
lines=$(tput lines)
|
||||||
cols=$(tput cols)
|
cols=$(tput cols)
|
||||||
|
|
||||||
|
@ -241,40 +234,37 @@ preview_file () {
|
||||||
if exists tree; then
|
if exists tree; then
|
||||||
fifo_pager tree --filelimit "$(find . -maxdepth 1 | wc -l)" -L 3 -C -F --dirsfirst --noreport
|
fifo_pager tree --filelimit "$(find . -maxdepth 1 | wc -l)" -L 3 -C -F --dirsfirst --noreport
|
||||||
elif exists exa; then
|
elif exists exa; then
|
||||||
exa -G --colour=always 2>/dev/null
|
exa -G --group-directories-first --colour=always
|
||||||
else
|
else
|
||||||
fifo_pager ls -F --directories-first --color=always
|
fifo_pager ls -F --group-directories-first --color=always
|
||||||
fi
|
fi
|
||||||
elif [ "${encoding#*)}" = "binary" ]; then
|
elif [ "${encoding#*)}" = "binary" ]; then
|
||||||
handle_mime "$1" "$mimetype" "$ext" "bin"
|
handle_mime "$1" "$mimetype" "$ext" "bin"
|
||||||
else
|
else
|
||||||
handle_mime "$1" "$mimetype" "$ext"
|
handle_mime "$1" "$mimetype" "$ext"
|
||||||
fi
|
fi
|
||||||
}
|
} 2>/dev/null
|
||||||
|
|
||||||
image_preview() {
|
image_preview() {
|
||||||
if [ "$TERMINAL" = "kitty" ]; then
|
if [ "$TERMINAL" = "kitty" ]; then
|
||||||
# Kitty terminal users can use the native image preview method although one might consider
|
# Kitty terminal users can use the native image preview method
|
||||||
# installing ueberzug and moving the ueberzug clause to the top since it performs alot better.
|
|
||||||
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 [ -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")" && "$QLPATH" "$f" && return
|
||||||
elif exists ueberzug; then
|
elif exists ueberzug; then
|
||||||
ueberzug_layer "$1" "$2" "$3"
|
ueberzug_layer "$1" "$2" "$3" && return
|
||||||
elif exists catimg; then
|
elif exists catimg; then
|
||||||
catimg "$3" &
|
catimg "$3" &
|
||||||
printf "%s" "$!" > "$IMGPID"
|
|
||||||
elif exists viu; then
|
elif exists viu; then
|
||||||
viu -t "$3" &
|
viu -t "$3" &
|
||||||
printf "%s" "$!" > "$IMGPID"
|
|
||||||
else
|
else
|
||||||
fifo_pager print_bin_info "$3"
|
fifo_pager print_bin_info "$3" && return
|
||||||
fi
|
fi
|
||||||
}
|
printf "%s" "$!" > "$IMGPID"
|
||||||
|
} 2>/dev/null
|
||||||
|
|
||||||
ueberzug_layer() {
|
ueberzug_layer() {
|
||||||
printf '{"action": "add", "identifier": "nnn_ueberzug", "x": 0, "y": 0, "width": "%s", "height": "%s", "scaler": "fit_contain", "path": "%s"}\n' "$1" "$2" "$3" > "$FIFO_UEBERZUG"
|
printf '{"action": "add", "identifier": "nnn_ueberzug", "x": 0, "y": 0, "width": "%d", "height": "%d", "scaler": "fit_contain", "path": "%s"}\n' "$1" "$2" "$3" > "$FIFO_UEBERZUG"
|
||||||
}
|
}
|
||||||
|
|
||||||
ueberzug_remove() {
|
ueberzug_remove() {
|
||||||
|
@ -283,46 +273,40 @@ ueberzug_remove() {
|
||||||
|
|
||||||
ueberzug_refresh() {
|
ueberzug_refresh() {
|
||||||
clear
|
clear
|
||||||
kill "$(cat "$IMGPID" 2>/dev/null)" >/dev/null 2>&1
|
kill "$(cat "$IMGPID")"
|
||||||
pkill -P "$$" >/dev/null 2>&1
|
kill "$(cat "$PAGERPID")"
|
||||||
pkill -f -n preview-tui-ext >/dev/null 2>&1
|
pkill -P "$$"
|
||||||
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
||||||
printf "\n" > "$NNN_FIFO"
|
cat "$CURSEL" > "$NNN_FIFO"
|
||||||
preview_fifo 2>/dev/null &
|
preview_fifo &
|
||||||
preview_file "$(cat "$CURSEL")"
|
preview_file "$(cat "$CURSEL")"
|
||||||
wait
|
wait "$!"
|
||||||
}
|
} 2>/dev/null
|
||||||
|
|
||||||
preview_fifo() {
|
preview_fifo() {
|
||||||
# use cat instead of 'exec <' to avoid issues with dash shell
|
printf "%s" "$$" > "$FIFOPID"
|
||||||
# shellcheck disable=SC2002
|
|
||||||
cat "$NNN_FIFO" |\
|
|
||||||
while read -r selection; do
|
while read -r selection; do
|
||||||
kill "$(cat "$IMGPID" 2>/dev/null)" >/dev/null 2>&1
|
kill "$(cat "$IMGPID")"
|
||||||
kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
|
kill "$(cat "$PAGERPID")"
|
||||||
[ "$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 < "$NNN_FIFO"
|
||||||
kill "$(cat "$IMGPID" 2>/dev/null)" >/dev/null 2>&1
|
} 2>/dev/null
|
||||||
kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
|
|
||||||
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
|
|
||||||
rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" >/dev/null 2>&1
|
|
||||||
pkill -P "$$" >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ "$PREVIEW_MODE" ]; then
|
if [ "$PREVIEW_MODE" ]; then
|
||||||
if [ "$TERMINAL" != "kitty" ] && exists ueberzug; then
|
if [ "$TERMINAL" != "kitty" ] && exists ueberzug; then
|
||||||
mkfifo "$FIFO_UEBERZUG"
|
mkfifo "$FIFO_UEBERZUG"
|
||||||
trap 'ueberzug_refresh; rm "$FIFO_UEBERZUG"' WINCH
|
trap 'ueberzug_refresh' WINCH
|
||||||
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
||||||
fi
|
fi
|
||||||
trap 'rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" 2>/dev/null' INT HUP EXIT
|
|
||||||
|
|
||||||
|
printf "%s" "$PWD/$1" > "$CURSEL"
|
||||||
preview_file "$PWD/$1"
|
preview_file "$PWD/$1"
|
||||||
printf "%s" "$PWD/$1" > "$CURSEL" &
|
preview_fifo &
|
||||||
preview_fifo 2>/dev/null &
|
wait "$!"
|
||||||
wait
|
rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" "$FIFOPID" 2>/dev/null
|
||||||
|
pkill -P "$$"
|
||||||
else
|
else
|
||||||
if [ ! -r "$NNN_FIFO" ]; then
|
if [ ! -r "$NNN_FIFO" ]; then
|
||||||
clear
|
clear
|
||||||
|
@ -333,6 +317,6 @@ else
|
||||||
printf "\$KITTY_LISTEN_ON not set!\nPlease read Usage in preview-tui."
|
printf "\$KITTY_LISTEN_ON not set!\nPlease read Usage in preview-tui."
|
||||||
cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg"
|
cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg"
|
||||||
else
|
else
|
||||||
togglepreview "$1" &
|
toggle_preview "$1" &
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -72,25 +72,26 @@
|
||||||
# Shell: POSIX compliant
|
# Shell: POSIX compliant
|
||||||
# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero, Luuk van Baal
|
# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero, Luuk van Baal
|
||||||
|
|
||||||
SPLIT="$SPLIT" # you can set a permanent split here
|
#SPLIT="$SPLIT" # you can set a permanent split here
|
||||||
TERMINAL="$TERMINAL" # same goes for the terminal
|
#TERMINAL="$TERMINAL" # same goes for the terminal
|
||||||
USE_SCOPE="${USE_SCOPE:-0}"
|
USE_SCOPE="${USE_SCOPE:-0}"
|
||||||
USE_PISTOL="${USE_PISTOL:-0}"
|
USE_PISTOL="${USE_PISTOL:-0}"
|
||||||
ICONLOOKUP="${ICONLOOKUP:-0}"
|
ICONLOOKUP="${ICONLOOKUP:-0}"
|
||||||
PAGER="${PAGER:-less -P?n -R}"
|
PAGER="${PAGER:-less -P?n -R}"
|
||||||
TMPDIR="${TMPDIR:-/tmp}"
|
TMPDIR="${TMPDIR:-/tmp}"
|
||||||
|
BAT_STYLE="${BAT_STYLE:-numbers}"
|
||||||
# Consider setting NNN_PREVIEWDIR to $XDG_CACHE_HOME/nnn/previews if you want to keep previews on disk between reboots
|
# Consider setting NNN_PREVIEWDIR to $XDG_CACHE_HOME/nnn/previews if you want to keep previews on disk between reboots
|
||||||
NNN_PREVIEWDIR="${NNN_PREVIEWDIR:-$TMPDIR/nnn/previews}"
|
NNN_PREVIEWDIR="${NNN_PREVIEWDIR:-$TMPDIR/nnn/previews}"
|
||||||
NNN_PREVIEWWIDTH="${NNN_PREVIEWWIDTH:-1920}"
|
NNN_PREVIEWWIDTH="${NNN_PREVIEWWIDTH:-1920}"
|
||||||
NNN_PREVIEWHEIGHT="${NNN_PREVIEWHEIGHT:-1080}"
|
NNN_PREVIEWHEIGHT="${NNN_PREVIEWHEIGHT:-1080}"
|
||||||
|
NNN_PARENT="${NNN_FIFO#*.}"
|
||||||
|
FIFOPID="$TMPDIR/nnn-preview-tui-fifopid.$NNN_PARENT"
|
||||||
|
PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NNN_PARENT"
|
||||||
|
IMGPID="$TMPDIR/nnn-preview-tui-imgpid.$NNN_PARENT"
|
||||||
|
CURSEL="$TMPDIR/nnn-preview-tui-selection.$NNN_PARENT"
|
||||||
|
FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NNN_PARENT"
|
||||||
|
|
||||||
startpreview() {
|
start_preview() {
|
||||||
NUMPREVIEWTUI="$(($(find "$TMPDIR" -maxdepth 1 -name 'nnn-preview-tui-pagerpid*' 2>/dev/null | wc -l) + 1))"
|
|
||||||
PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NUMPREVIEWTUI"
|
|
||||||
IMGPID="$TMPDIR/nnn-preview-tui-gifpid.$NUMPREVIEWTUI"
|
|
||||||
CURSEL="$TMPDIR/nnn-preview-tui-selection.$NUMPREVIEWTUI"
|
|
||||||
FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NUMPREVIEWTUI"
|
|
||||||
|
|
||||||
[ "$PAGER" = "most" ] && PAGER="less -R"
|
[ "$PAGER" = "most" ] && PAGER="less -R"
|
||||||
|
|
||||||
if [ -e "${TMUX%%,*}" ] && tmux -V | grep -q '[ -][3456789]\.'; then
|
if [ -e "${TMUX%%,*}" ] && tmux -V | grep -q '[ -][3456789]\.'; then
|
||||||
|
@ -107,22 +108,18 @@ startpreview() {
|
||||||
SPLIT='v'
|
SPLIT='v'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$TERMINAL" = "tmux" ]; then
|
case "$TERMINAL" in
|
||||||
# tmux splits are inverted
|
tmux) # tmux splits are inverted
|
||||||
if [ "$SPLIT" = "v" ]; then SPLIT="h"; else SPLIT="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 "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 "BAT_STYLE=${BAT_STYLE:-numbers}" -e "PAGERPID=$PAGERPID" \
|
-e "BAT_STYLE=$BAT_STYLE" -e "PAGERPID=$PAGERPID" -e "FIFOPID=$FIFOPID" \
|
||||||
-e "IMGPID=$IMGPID" -e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" \
|
-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"$DSPLIT" "$0" "$1" ;;
|
||||||
elif [ "$TERMINAL" = "kitty" ]; then
|
kitty) # Setting the layout for the new window. It will be restored after the script ends.
|
||||||
# Setting the layout for the new window. It will be restored after the
|
kitty @ goto-layout splits
|
||||||
# script ends.
|
|
||||||
kitty @ goto-layout splits >/dev/null
|
|
||||||
|
|
||||||
# Trying to use kitty's integrated window management as the split window.
|
# Trying to use kitty's integrated window management as the split window.
|
||||||
# All environmental variables that will be used in the new window must
|
# All environmental variables that will be used in the new window must
|
||||||
# be explicitly passed.
|
# be explicitly passed.
|
||||||
|
@ -130,36 +127,37 @@ startpreview() {
|
||||||
--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 "USE_PISTOL=$USE_PISTOL" --env "BAT_STYLE=${BAT_STYLE:-numbers}" \
|
--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 "PAGERPID=$PAGERPID" --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" ;;
|
||||||
elif [ -n "$2" ]; then
|
*) if [ -n "$2" ]; then
|
||||||
QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" >/dev/null &
|
QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" &
|
||||||
else
|
else
|
||||||
PAGERPID="$PAGERPID" IMGPID="$IMGPID" 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 &
|
FIFOPID="$FIFOPID" FIFO_UEBERZUG="$FIFO_UEBERZUG" $TERMINAL -e "$0" "$1" &
|
||||||
fi
|
fi ;;
|
||||||
}
|
esac
|
||||||
|
} >/dev/null 2>&1
|
||||||
|
|
||||||
togglepreview() {
|
toggle_preview() {
|
||||||
if exists QuickLook.exe; then
|
if exists QuickLook.exe; then
|
||||||
QLPATH="QuickLook.exe"
|
QLPATH="QuickLook.exe"
|
||||||
elif exists Bridge.exe; then
|
elif exists Bridge.exe; then
|
||||||
QLPATH="Bridge.exe"
|
QLPATH="Bridge.exe"
|
||||||
fi
|
fi
|
||||||
if pkill -fx "cat $NNN_FIFO" >/dev/null; then
|
if pkill -P "$(cat "$FIFOPID")"; then
|
||||||
if [ -n "$QLPATH" ] && stat "$1" >/dev/null 2>&1; then
|
if [ -n "$QLPATH" ] && stat "$1"; then
|
||||||
f="$(wslpath -w "$1" 2>&1)" && "$QLPATH" "$f" &
|
f="$(wslpath -w "$1")" && "$QLPATH" "$f" &
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
startpreview "$1" "$QLPATH"
|
start_preview "$1" "$QLPATH"
|
||||||
fi
|
fi
|
||||||
}
|
} >/dev/null 2>&1
|
||||||
|
|
||||||
exists() {
|
exists() {
|
||||||
type "$1" >/dev/null 2>&1
|
type "$1" >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
fifo_pager() {
|
fifo_pager() {
|
||||||
|
@ -178,7 +176,7 @@ fifo_pager() {
|
||||||
if [ "$cmd" = "pager" ]; then
|
if [ "$cmd" = "pager" ]; then
|
||||||
if exists bat; then
|
if exists bat; then
|
||||||
bat --terminal-width="$(tput cols)" --decorations=always --color=always \
|
bat --terminal-width="$(tput cols)" --decorations=always --color=always \
|
||||||
--paging=never --style="${BAT_STYLE:-numbers}" "$@" 2>/dev/null &
|
--paging=never --style="$BAT_STYLE" "$@" &
|
||||||
else
|
else
|
||||||
$PAGER "$@" &
|
$PAGER "$@" &
|
||||||
fi
|
fi
|
||||||
|
@ -188,13 +186,13 @@ fifo_pager() {
|
||||||
)
|
)
|
||||||
|
|
||||||
rm "$tmpfifopath"
|
rm "$tmpfifopath"
|
||||||
}
|
} 2>/dev/null
|
||||||
|
|
||||||
# Binary file: show file info inside the pager
|
# Binary file: show file info inside the pager
|
||||||
print_bin_info() {
|
print_bin_info() {
|
||||||
printf -- "-------- \033[1;31mBinary file\033[0m --------\n"
|
printf -- "-------- \033[1;31mBinary file\033[0m --------\n"
|
||||||
if exists mediainfo; then
|
if exists mediainfo; then
|
||||||
mediainfo "$1" 2>/dev/null
|
mediainfo "$1"
|
||||||
else
|
else
|
||||||
file -b "$1"
|
file -b "$1"
|
||||||
fi
|
fi
|
||||||
|
@ -267,19 +265,17 @@ preview_file() {
|
||||||
|
|
||||||
# Trying to use scope.sh if it's available.
|
# Trying to use scope.sh if it's available.
|
||||||
if [ "$USE_SCOPE" -ne 0 ] && exists scope.sh; then
|
if [ "$USE_SCOPE" -ne 0 ] && exists scope.sh; then
|
||||||
fifo_pager scope.sh "$1" "$cols" "$lines" "$(mktemp -d)" \
|
fifo_pager scope.sh "$1" "$cols" "$lines" "$(mktemp -d)" "True"
|
||||||
"True" 2>/dev/null
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use QuickLook if it's available.
|
# Use QuickLook if it's available.
|
||||||
if [ -n "$QUICKLOOK" ]; then
|
if [ -n "$QUICKLOOK" ]; then
|
||||||
stat "$1" >/dev/null 2>&1 && f="$(wslpath -w "$1" 2>&1)" && "$QLPATH" "$f" &
|
stat "$1" && f="$(wslpath -w "$1")" && "$QLPATH" "$f" &
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Detecting the exact type of the file: the encoding, mime type, and
|
# Detecting the exact exists of the file: the encoding, mime type, and extension in lowercase.
|
||||||
# extension in lowercase.
|
|
||||||
encoding="$(file -bL --mime-encoding -- "$1")"
|
encoding="$(file -bL --mime-encoding -- "$1")"
|
||||||
mimetype="$(file -bL --mime-type -- "$1")"
|
mimetype="$(file -bL --mime-type -- "$1")"
|
||||||
ext="${1##*.}"
|
ext="${1##*.}"
|
||||||
|
@ -291,14 +287,13 @@ preview_file() {
|
||||||
if [ -d "$1" ]; then
|
if [ -d "$1" ]; then
|
||||||
cd "$1" || return
|
cd "$1" || return
|
||||||
if [ "$ICONLOOKUP" -ne 0 ] && [ -f "$(dirname "$0")"/.iconlookup ]; then
|
if [ "$ICONLOOKUP" -ne 0 ] && [ -f "$(dirname "$0")"/.iconlookup ]; then
|
||||||
[ "$SPLIT" = h ] && [ "$TERMINAL" != "kitty" ] && BSTR="\n"
|
[ "$SPLIT" = v ] && BSTR="\n"
|
||||||
[ "$SPLIT" = v ] && [ "$TERMINAL" = "kitty" ] && BSTR="\n"
|
|
||||||
# shellcheck disable=SC2012
|
# shellcheck disable=SC2012
|
||||||
ls -F --group-directories-first | head -n "$((lines - 3))" | "$(dirname "$0")"/.iconlookup -l "$cols" -B "$BSTR" -b " "
|
ls -F --group-directories-first | head -n "$((lines - 3))" | "$(dirname "$0")"/.iconlookup -l "$cols" -B "$BSTR" -b " "
|
||||||
elif exists tree; then
|
elif exists tree; then
|
||||||
fifo_pager tree --filelimit "$(find . -maxdepth 1 | wc -l)" -L 3 -C -F --dirsfirst --noreport
|
fifo_pager tree --filelimit "$(find . -maxdepth 1 | wc -l)" -L 3 -C -F --dirsfirst --noreport
|
||||||
elif exists exa; then
|
elif exists exa; then
|
||||||
exa -G --group-directories-first --colour=always 2>/dev/null
|
exa -G --group-directories-first --colour=always
|
||||||
else
|
else
|
||||||
fifo_pager ls -F --group-directories-first --color=always
|
fifo_pager ls -F --group-directories-first --color=always
|
||||||
fi
|
fi
|
||||||
|
@ -307,17 +302,17 @@ preview_file() {
|
||||||
else
|
else
|
||||||
handle_mime "$1" "$mimetype" "$ext"
|
handle_mime "$1" "$mimetype" "$ext"
|
||||||
fi
|
fi
|
||||||
}
|
} 2>/dev/null
|
||||||
|
|
||||||
generate_preview() {
|
generate_preview() {
|
||||||
if [ -n "$QLPATH" ] && stat "$3" >/dev/null 2>&1; then
|
if [ -n "$QLPATH" ] && stat "$3"; then
|
||||||
f="$(wslpath -w "$3" 2>&1)" && "$QLPATH" "$f" &
|
f="$(wslpath -w "$3")" && "$QLPATH" "$f" &
|
||||||
elif [ ! -f "$NNN_PREVIEWDIR/$3.jpg" ] || [ -n "$(find -L "$3" -newer "$NNN_PREVIEWDIR/$3.jpg")" ]; then
|
elif [ ! -f "$NNN_PREVIEWDIR/$3.jpg" ] || [ -n "$(find -L "$3" -newer "$NNN_PREVIEWDIR/$3.jpg")" ]; then
|
||||||
mkdir -p "$NNN_PREVIEWDIR/${3%/*}"
|
mkdir -p "$NNN_PREVIEWDIR/${3%/*}"
|
||||||
case $4 in
|
case $4 in
|
||||||
audio) ffmpeg -i "$3" -filter_complex "scale=iw*min(1\,min($NNN_PREVIEWWIDTH/iw\,ih)):-1" "$NNN_PREVIEWDIR/$3.jpg" -y >/dev/null 2>&1 ;;
|
audio) ffmpeg -i "$3" -filter_complex "scale=iw*min(1\,min($NNN_PREVIEWWIDTH/iw\,ih)):-1" "$NNN_PREVIEWDIR/$3.jpg" -y ;;
|
||||||
epub) gnome-epub-thumbnailer "$3" "$NNN_PREVIEWDIR/$3.jpg" >/dev/null 2>&1 ;;
|
epub) gnome-epub-thumbnailer "$3" "$NNN_PREVIEWDIR/$3.jpg" ;;
|
||||||
font) fontpreview -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" >/dev/null 2>&1 ;;
|
font) fontpreview -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" ;;
|
||||||
gif) if exists ueberzug && exists convert && [ "$TERMINAL" != "kitty" ]; then
|
gif) if exists ueberzug && exists convert && [ "$TERMINAL" != "kitty" ]; then
|
||||||
if [ ! -d "$NNN_PREVIEWDIR/$3" ]; then
|
if [ ! -d "$NNN_PREVIEWDIR/$3" ]; then
|
||||||
mkdir -p "$NNN_PREVIEWDIR/$3"
|
mkdir -p "$NNN_PREVIEWDIR/$3"
|
||||||
|
@ -336,11 +331,11 @@ generate_preview() {
|
||||||
return
|
return
|
||||||
fi ;;
|
fi ;;
|
||||||
image) convert "$3" -flatten -resize "$NNN_PREVIEWWIDTH"x"$NNN_PREVIEWHEIGHT"\> "$NNN_PREVIEWDIR/$3.jpg" ;;
|
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
|
office) libreoffice --convert-to jpg "$3" --outdir "$NNN_PREVIEWDIR/${3%/*}"
|
||||||
filename="$(printf "%s" "${3##*/}" | cut -d. -f1)"
|
filename="$(printf "%s" "${3##*/}" | cut -d. -f1)"
|
||||||
mv "$NNN_PREVIEWDIR/${3%/*}/$filename.jpg" "$NNN_PREVIEWDIR/$3.jpg" ;;
|
mv "$NNN_PREVIEWDIR/${3%/*}/$filename.jpg" "$NNN_PREVIEWDIR/$3.jpg" ;;
|
||||||
pdf) pdftoppm -jpeg -f 1 -singlefile "$3" "$NNN_PREVIEWDIR/$3" >/dev/null 2>&1 ;;
|
pdf) pdftoppm -jpeg -f 1 -singlefile "$3" "$NNN_PREVIEWDIR/$3" ;;
|
||||||
video) ffmpegthumbnailer -s0 -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" >/dev/null 2>&1 || rm "$NNN_PREVIEWDIR/$3.jpg" ;;
|
video) ffmpegthumbnailer -s0 -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" || rm "$NNN_PREVIEWDIR/$3.jpg" ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
if [ -f "$NNN_PREVIEWDIR/$3.jpg" ]; then
|
if [ -f "$NNN_PREVIEWDIR/$3.jpg" ]; then
|
||||||
|
@ -348,30 +343,27 @@ generate_preview() {
|
||||||
else
|
else
|
||||||
fifo_pager print_bin_info "$3"
|
fifo_pager print_bin_info "$3"
|
||||||
fi
|
fi
|
||||||
}
|
} >/dev/null 2>&1
|
||||||
|
|
||||||
image_preview() {
|
image_preview() {
|
||||||
clear
|
clear
|
||||||
if [ "$TERMINAL" = "kitty" ]; then
|
if [ "$TERMINAL" = "kitty" ]; then
|
||||||
# Kitty terminal users can use the native image preview method although one might consider
|
# Kitty terminal users can use the native image preview method
|
||||||
# installing ueberzug and moving the ueberzug clause to the top since it performs alot better.
|
|
||||||
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" && return
|
||||||
elif exists catimg; then
|
elif exists catimg; then
|
||||||
catimg "$3" &
|
catimg "$3" &
|
||||||
printf "%s" "$!" > "$IMGPID"
|
|
||||||
elif exists viu; then
|
elif exists viu; then
|
||||||
viu -t "$3" &
|
viu -t "$3" &
|
||||||
printf "%s" "$!" > "$IMGPID"
|
|
||||||
else
|
else
|
||||||
fifo_pager print_bin_info "$3"
|
fifo_pager print_bin_info "$3" && return
|
||||||
fi
|
fi
|
||||||
}
|
printf "%s" "$!" > "$IMGPID"
|
||||||
|
} 2>/dev/null
|
||||||
|
|
||||||
ueberzug_layer() {
|
ueberzug_layer() {
|
||||||
printf '{"action": "add", "identifier": "nnn_ueberzug", "x": 0, "y": 0, "width": "%s", "height": "%s", "scaler": "fit_contain", "path": "%s"}\n' "$1" "$2" "$3" > "$FIFO_UEBERZUG"
|
printf '{"action": "add", "identifier": "nnn_ueberzug", "x": 0, "y": 0, "width": "%d", "height": "%d", "scaler": "fit_contain", "path": "%s"}\n' "$1" "$2" "$3" > "$FIFO_UEBERZUG"
|
||||||
}
|
}
|
||||||
|
|
||||||
ueberzug_remove() {
|
ueberzug_remove() {
|
||||||
|
@ -380,46 +372,40 @@ ueberzug_remove() {
|
||||||
|
|
||||||
ueberzug_refresh() {
|
ueberzug_refresh() {
|
||||||
clear
|
clear
|
||||||
kill "$(cat "$IMGPID" 2>/dev/null)" >/dev/null 2>&1
|
kill "$(cat "$IMGPID")"
|
||||||
pkill -P "$$" >/dev/null 2>&1
|
kill "$(cat "$PAGERPID")"
|
||||||
pkill -f -n preview-tui-ext >/dev/null 2>&1
|
pkill -P "$$"
|
||||||
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
||||||
printf "\n" > "$NNN_FIFO"
|
cat "$CURSEL" > "$NNN_FIFO"
|
||||||
preview_fifo 2>/dev/null &
|
preview_fifo &
|
||||||
preview_file "$(cat "$CURSEL")"
|
preview_file "$(cat "$CURSEL")"
|
||||||
wait
|
wait "$!"
|
||||||
}
|
} 2>/dev/null
|
||||||
|
|
||||||
preview_fifo() {
|
preview_fifo() {
|
||||||
# use cat instead of 'exec <' to avoid issues with dash shell
|
printf "%s" "$$" > "$FIFOPID"
|
||||||
# shellcheck disable=SC2002
|
|
||||||
cat "$NNN_FIFO" |\
|
|
||||||
while read -r selection; do
|
while read -r selection; do
|
||||||
kill "$(cat "$IMGPID" 2>/dev/null)" >/dev/null 2>&1
|
kill "$(cat "$IMGPID")"
|
||||||
kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
|
kill "$(cat "$PAGERPID")"
|
||||||
[ "$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 < "$NNN_FIFO"
|
||||||
kill "$(cat "$IMGPID" 2>/dev/null)" >/dev/null 2>&1
|
} 2>/dev/null
|
||||||
kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
|
|
||||||
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
|
|
||||||
rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" >/dev/null 2>&1
|
|
||||||
pkill -P "$$" >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ "$PREVIEW_MODE" ]; then
|
if [ "$PREVIEW_MODE" ]; then
|
||||||
if [ "$TERMINAL" != "kitty" ] && exists ueberzug; then
|
if [ "$TERMINAL" != "kitty" ] && exists ueberzug; then
|
||||||
mkfifo "$FIFO_UEBERZUG"
|
mkfifo "$FIFO_UEBERZUG"
|
||||||
trap 'ueberzug_refresh; rm "$FIFO_UEBERZUG"' WINCH
|
trap 'ueberzug_refresh' WINCH
|
||||||
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
||||||
fi
|
fi
|
||||||
trap 'rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" 2>/dev/null' INT HUP EXIT
|
|
||||||
|
|
||||||
|
printf "%s" "$PWD/$1" > "$CURSEL"
|
||||||
preview_file "$PWD/$1"
|
preview_file "$PWD/$1"
|
||||||
printf "%s" "$PWD/$1" > "$CURSEL" &
|
preview_fifo &
|
||||||
preview_fifo 2>/dev/null &
|
wait "$!"
|
||||||
wait
|
rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" "$FIFOPID" 2>/dev/null
|
||||||
|
pkill -P "$$"
|
||||||
else
|
else
|
||||||
if [ ! -r "$NNN_FIFO" ]; then
|
if [ ! -r "$NNN_FIFO" ]; then
|
||||||
clear
|
clear
|
||||||
|
@ -430,6 +416,6 @@ else
|
||||||
printf "\$KITTY_LISTEN_ON not set!\nPlease read Usage in preview-tui-ext."
|
printf "\$KITTY_LISTEN_ON not set!\nPlease read Usage in preview-tui-ext."
|
||||||
cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg"
|
cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg"
|
||||||
else
|
else
|
||||||
togglepreview "$1" &
|
toggle_preview "$1" &
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue