mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
commit
bb5642291c
|
@ -249,7 +249,7 @@ 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 "$3" &
|
kitty +kitten icat --silent --place "$1"x"$2"@0x0 --transfer-mode=stream --stdin=no "$3" &
|
||||||
elif [ -n "$QLPATH" ] && stat "$3" >/dev/null 2>&1; then
|
elif [ -n "$QLPATH" ] && stat "$3"; then
|
||||||
f="$(wslpath -w "$3")" && "$QLPATH" "$f" && return
|
f="$(wslpath -w "$3")" && "$QLPATH" "$f" && return
|
||||||
elif exists ueberzug; then
|
elif exists ueberzug; then
|
||||||
ueberzug_layer "$1" "$2" "$3" && return
|
ueberzug_layer "$1" "$2" "$3" && return
|
||||||
|
@ -271,24 +271,22 @@ ueberzug_remove() {
|
||||||
printf '{"action": "remove", "identifier": "nnn_ueberzug"}\n' > "$FIFO_UEBERZUG"
|
printf '{"action": "remove", "identifier": "nnn_ueberzug"}\n' > "$FIFO_UEBERZUG"
|
||||||
}
|
}
|
||||||
|
|
||||||
ueberzug_refresh() {
|
winch_handler() {
|
||||||
clear
|
clear
|
||||||
kill "$(cat "$IMGPID")"
|
kill "$(cat "$IMGPID")" "$(cat "$PAGERPID")"
|
||||||
kill "$(cat "$PAGERPID")"
|
|
||||||
pkill -P "$$"
|
pkill -P "$$"
|
||||||
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
if [ -p "$FIFO_UEBERZUG" ]; then tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json & fi
|
||||||
cat "$CURSEL" > "$NNN_FIFO"
|
cat "$CURSEL" > "$NNN_FIFO"
|
||||||
preview_fifo &
|
|
||||||
preview_file "$(cat "$CURSEL")"
|
preview_file "$(cat "$CURSEL")"
|
||||||
|
preview_fifo &
|
||||||
wait "$!"
|
wait "$!"
|
||||||
} 2>/dev/null
|
} 2>/dev/null
|
||||||
|
|
||||||
preview_fifo() {
|
preview_fifo() {
|
||||||
printf "%s" "$$" > "$FIFOPID"
|
printf "%s" "$$" > "$FIFOPID"
|
||||||
while read -r selection; do
|
while read -r selection; do
|
||||||
kill "$(cat "$IMGPID")"
|
kill "$(cat "$IMGPID")" "$(cat "$PAGERPID")"
|
||||||
kill "$(cat "$PAGERPID")"
|
[ -p "$FIFO_UEBERZUG" ] && ueberzug_remove
|
||||||
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
|
|
||||||
preview_file "$selection"
|
preview_file "$selection"
|
||||||
printf "%s" "$selection" > "$CURSEL"
|
printf "%s" "$selection" > "$CURSEL"
|
||||||
done < "$NNN_FIFO"
|
done < "$NNN_FIFO"
|
||||||
|
@ -297,16 +295,15 @@ preview_fifo() {
|
||||||
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' WINCH
|
|
||||||
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "%s" "$PWD/$1" > "$CURSEL"
|
printf "%s" "$PWD/$1" > "$CURSEL"
|
||||||
preview_file "$PWD/$1"
|
preview_file "$PWD/$1"
|
||||||
preview_fifo &
|
preview_fifo &
|
||||||
|
trap 'winch_handler' WINCH
|
||||||
|
trap 'rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" "$FIFOPID" 2>/dev/null' INT HUP EXIT
|
||||||
wait "$!" 2>/dev/null
|
wait "$!" 2>/dev/null
|
||||||
pkill -P "$$"
|
|
||||||
rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" "$FIFOPID" 2>/dev/null
|
|
||||||
else
|
else
|
||||||
if [ ! -r "$NNN_FIFO" ]; then
|
if [ ! -r "$NNN_FIFO" ]; then
|
||||||
clear
|
clear
|
||||||
|
|
|
@ -313,7 +313,7 @@ generate_preview() {
|
||||||
audio) ffmpeg -i "$3" -filter_complex "scale=iw*min(1\,min($NNN_PREVIEWWIDTH/iw\,ih)):-1" "$NNN_PREVIEWDIR/$3.jpg" -y ;;
|
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" ;;
|
epub) gnome-epub-thumbnailer "$3" "$NNN_PREVIEWDIR/$3.jpg" ;;
|
||||||
font) fontpreview -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" ;;
|
font) fontpreview -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" ;;
|
||||||
gif) if exists ueberzug && exists convert && [ "$TERMINAL" != "kitty" ]; then
|
gif) if [ -p "$FIFO_UEBERZUG" ] && exists convert; then
|
||||||
if [ ! -d "$NNN_PREVIEWDIR/$3" ]; then
|
if [ ! -d "$NNN_PREVIEWDIR/$3" ]; then
|
||||||
mkdir -p "$NNN_PREVIEWDIR/$3"
|
mkdir -p "$NNN_PREVIEWDIR/$3"
|
||||||
convert -coalesce -resize "$NNN_PREVIEWWIDTH"x"$NNN_PREVIEWHEIGHT"\> "$3" "$NNN_PREVIEWDIR/$3/${3##*/}.jpg"
|
convert -coalesce -resize "$NNN_PREVIEWWIDTH"x"$NNN_PREVIEWHEIGHT"\> "$3" "$NNN_PREVIEWDIR/$3/${3##*/}.jpg"
|
||||||
|
@ -337,13 +337,13 @@ generate_preview() {
|
||||||
pdf) pdftoppm -jpeg -f 1 -singlefile "$3" "$NNN_PREVIEWDIR/$3" ;;
|
pdf) pdftoppm -jpeg -f 1 -singlefile "$3" "$NNN_PREVIEWDIR/$3" ;;
|
||||||
video) ffmpegthumbnailer -s0 -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" || rm "$NNN_PREVIEWDIR/$3.jpg" ;;
|
video) ffmpegthumbnailer -s0 -i "$3" -o "$NNN_PREVIEWDIR/$3.jpg" || rm "$NNN_PREVIEWDIR/$3.jpg" ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi >/dev/null
|
||||||
if [ -f "$NNN_PREVIEWDIR/$3.jpg" ]; then
|
if [ -f "$NNN_PREVIEWDIR/$3.jpg" ]; then
|
||||||
image_preview "$1" "$2" "$NNN_PREVIEWDIR/$3.jpg"
|
image_preview "$1" "$2" "$NNN_PREVIEWDIR/$3.jpg"
|
||||||
else
|
else
|
||||||
fifo_pager print_bin_info "$3"
|
fifo_pager print_bin_info "$3"
|
||||||
fi
|
fi
|
||||||
} >/dev/null 2>&1
|
} 2>/dev/null
|
||||||
|
|
||||||
image_preview() {
|
image_preview() {
|
||||||
clear
|
clear
|
||||||
|
@ -370,24 +370,22 @@ ueberzug_remove() {
|
||||||
printf '{"action": "remove", "identifier": "nnn_ueberzug"}\n' > "$FIFO_UEBERZUG"
|
printf '{"action": "remove", "identifier": "nnn_ueberzug"}\n' > "$FIFO_UEBERZUG"
|
||||||
}
|
}
|
||||||
|
|
||||||
ueberzug_refresh() {
|
winch_handler() {
|
||||||
clear
|
clear
|
||||||
kill "$(cat "$IMGPID")"
|
kill "$(cat "$IMGPID")" "$(cat "$PAGERPID")"
|
||||||
kill "$(cat "$PAGERPID")"
|
|
||||||
pkill -P "$$"
|
pkill -P "$$"
|
||||||
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
if [ -p "$FIFO_UEBERZUG" ]; then tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json & fi
|
||||||
cat "$CURSEL" > "$NNN_FIFO"
|
cat "$CURSEL" > "$NNN_FIFO"
|
||||||
preview_fifo &
|
|
||||||
preview_file "$(cat "$CURSEL")"
|
preview_file "$(cat "$CURSEL")"
|
||||||
|
preview_fifo &
|
||||||
wait "$!"
|
wait "$!"
|
||||||
} 2>/dev/null
|
} 2>/dev/null
|
||||||
|
|
||||||
preview_fifo() {
|
preview_fifo() {
|
||||||
printf "%s" "$$" > "$FIFOPID"
|
printf "%s" "$$" > "$FIFOPID"
|
||||||
while read -r selection; do
|
while read -r selection; do
|
||||||
kill "$(cat "$IMGPID")"
|
kill "$(cat "$IMGPID")" "$(cat "$PAGERPID")"
|
||||||
kill "$(cat "$PAGERPID")"
|
[ -p "$FIFO_UEBERZUG" ] && ueberzug_remove
|
||||||
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
|
|
||||||
preview_file "$selection"
|
preview_file "$selection"
|
||||||
printf "%s" "$selection" > "$CURSEL"
|
printf "%s" "$selection" > "$CURSEL"
|
||||||
done < "$NNN_FIFO"
|
done < "$NNN_FIFO"
|
||||||
|
@ -396,16 +394,15 @@ preview_fifo() {
|
||||||
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' WINCH
|
|
||||||
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "%s" "$PWD/$1" > "$CURSEL"
|
printf "%s" "$PWD/$1" > "$CURSEL"
|
||||||
preview_file "$PWD/$1"
|
preview_file "$PWD/$1"
|
||||||
preview_fifo &
|
preview_fifo &
|
||||||
|
trap 'winch_handler' WINCH
|
||||||
|
trap 'rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" "$FIFOPID" 2>/dev/null' INT HUP EXIT
|
||||||
wait "$!" 2>/dev/null
|
wait "$!" 2>/dev/null
|
||||||
pkill -P "$$"
|
|
||||||
rm "$PAGERPID" "$IMGPID" "$CURSEL" "$FIFO_UEBERZUG" "$FIFOPID" 2>/dev/null
|
|
||||||
else
|
else
|
||||||
if [ ! -r "$NNN_FIFO" ]; then
|
if [ ! -r "$NNN_FIFO" ]; then
|
||||||
clear
|
clear
|
||||||
|
|
Loading…
Reference in a new issue