| [picker](picker) | Pick files and list one per line (to pipe) | sh | nnn |
| [preview-tabbed](preview-tabbed) | Tabbed/xembed based file previewer | bash | _see in-file docs_ |
| [preview-tui](preview-tui) | Tmux/kitty/xterm/`$TERMINAL` based file previewer | sh | _see in-file docs_ |
+| [preview-tui-ext](preview-tui-ext) | Meant to be an exhaustive version of [preview-tui](preview-tui) | sh | _see in-file docs_ |
| [pskill](pskill) | Fuzzy list by name and kill process or zombie | sh | fzf, ps, sudo/doas |
| [renamer](renamer) | Batch rename selection or files in dir | sh | [qmv](https://www.nongnu.org/renameutils/)/[vidir](https://joeyh.name/code/moreutils/) |
| [ringtone](ringtone) | Create a variable bitrate mp3 ringtone from file | sh | date, ffmpeg |
# Description: Terminal based file previewer
#
# Note: This plugin needs a "NNN_FIFO" to work. See man.
-# For a more extended version of this script, including ueberzug support, see preview-tui-ext.
+# For a more extended version of this script with additional optional dependencies, see preview-tui-ext.
#
# Dependencies:
# - Supports 3 independent methods to preview with:
# without extra dependencies.
#
# Shell: POSIX compliant
-# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero
+# 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}"
USE_PISTOL="${USE_PISTOL:-0}"
-PAGER="${PAGER:-less -R}"
+PAGER="${PAGER:-less -P?n -R}"
TMPDIR="${TMPDIR:-/tmp}"
+NUMPREVIEWTUI="$(($(find "$TMPDIR" -maxdepth 1 -name 'nnn-preview-tui-pagerpid*' 2>/dev/null | wc -l) + 1))"
+PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NUMPREVIEWTUI"
+GIFPID="$TMPDIR/nnn-preview-tui-gifpid.$NUMPREVIEWTUI"
+FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NUMPREVIEWTUI"
+
[ "$PAGER" = "most" ] && PAGER="less -R"
if [ -e "${TMUX%%,*}" ] && tmux -V | grep -q '[ -][3456789]\.'; then
}
preview_file () {
- kill %- %+ 2>/dev/null && wait %- %+ 2>/dev/null
clear
-
# Trying to use pistol if it's available.
if [ "$USE_PISTOL" -ne 0 ] && exists pistol; then
fifo_pager pistol "$1"
if [ -d "$1" ]; then
cd "$1" || return
if exists tree; then
- fifo_pager tree -L 3 -F
+ fifo_pager tree -L 1 --dirsfirst -F -C
elif exists exa; then
fifo_pager exa -G --colour=always 2>/dev/null
else
ueberzug_layer "$1" "$2" "$3"
elif exists catimg; then
catimg "$3" &
- gifpid="$!"
+ echo "$!" > "$GIFPID"
elif exists viu; then
viu -t "$3" &
- gifpid="$!"
+ echo "$!" > "$GIFPID"
else
fifo_pager print_bin_info "$1"
fi
ueberzug_refresh() {
clear
- pkill -P "$$"
- pkill -f -n preview-tui
+ pkill -P "$$" >/dev/null 2>&1
+ pkill -f -n preview-tui-ext >/dev/null 2>&1
echo > "$NNN_FIFO"
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
preview_fifo &
}
if [ "$TERMINAL" != "kitty" ] && [ "$PREVIEW_MODE" ] && exists ueberzug; then
trap 'ueberzug_refresh' WINCH
- trap 'rm "$FIFO_UEBERZUG"' INT HUP EXIT
+ trap 'rm "$FIFO_UEBERZUG" "$PAGERPID" "$GIFPID"' INT HUP EXIT
fi
preview_fifo() {
# shellcheck disable=SC2002
cat "$NNN_FIFO" |\
while read -r selection; do
- [ "$gifpid" -ne 0 ] && kill "$gifpid"
+ kill "$(cat "$GIFPID" 2>/dev/null)" >/dev/null 2>&1
+ kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
preview_file "$selection"
done
[ "$TERMINAL" != "kitty" ] && exists ueberzug && rm "$FIFO_UEBERZUG"
+ rm "$PAGERPID" "$GIFPID" >/dev/null 2>&1
}
if [ "$PREVIEW_MODE" ]; then
# without extra dependencies.
#
# Shell: POSIX compliant
-# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero
+# 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
PAGER="${PAGER:-less -P?n -R}"
ARCHIVES="$(echo "$NNN_ARCHIVE" | sed 's/.*(\(.*\)).*/\1/;s/|/ /g')"
TMPDIR="${TMPDIR:-/tmp}"
+NUMPREVIEWTUI="$(($(find "$TMPDIR" -maxdepth 1 -name 'nnn-preview-tui-pagerpid*' 2>/dev/null | wc -l) + 1))"
+PAGERPID="$TMPDIR/nnn-preview-tui-pagerpid.$NUMPREVIEWTUI"
+GIFPID="$TMPDIR/nnn-preview-tui-gifpid.$NUMPREVIEWTUI"
+FIFO_UEBERZUG="$TMPDIR/nnn-preview-tui-ueberzug-fifo.$NUMPREVIEWTUI"
[ "$PAGER" = "most" ] && PAGER="less -R"
mkfifo "$tmpfifopath" || return
$PAGER < "$tmpfifopath" &
- pagerpid="$!"
+ echo "$!" > "$PAGERPID"
(
exec > "$tmpfifopath"
}
preview_file () {
- kill %- %+ 2>/dev/null && wait %- %+ 2>/dev/null
clear
-
# Trying to use pistol if it's available.
if [ "$USE_PISTOL" -ne 0 ] && exists pistol; then
fifo_pager pistol "$1"
generate_preview() {
if [ ! -f "$TMPDIR/$3.png" ]; then
- fifo_pager print_bin_info "$3"
+ [ "$4" != gif ] && fifo_pager print_bin_info "$3"
mkdir -p "$TMPDIR/${3%/*}"
case $4 in
audio) ffmpeg -i "$3" "$TMPDIR/$3.png" -y >/dev/null 2>&1 ;;
done
[ "$LOOP_GIFS" -eq 0 ] && return
done &
- gifpid="$!"
+ echo "$!" > "$GIFPID"
return
else
image_preview "$1" "$2" "$3"
pdf) pdftoppm -png -f 1 -singlefile "$3" "$TMPDIR/$3" >/dev/null 2>&1 ;;
video) ffmpegthumbnailer -i "$3" -o "$TMPDIR/$3.png" -s 0 -q 10 >/dev/null 2>&1 ;;
esac
- kill "$pagerpid"
fi
image_preview "$1" "$2" "$TMPDIR/$3.png"
}
image_preview() {
+ clear
if [ "$TERMINAL" = "kitty" ]; then
# Kitty terminal users can use the native image preview method.
kitty +kitten icat --silent --place "$1"x"$2"@0x0 --transfer-mode=stream --stdin=no \
ueberzug_layer "$1" "$2" "$3"
elif exists catimg; then
catimg "$3" &
- gifpid="$!"
+ echo "$!" > "$GIFPID"
elif exists viu; then
viu -t "$3" &
- gifpid="$!"
+ echo "$!" > "$GIFPID"
else
fifo_pager print_bin_info "$1"
fi
ueberzug_refresh() {
clear
- pkill -P "$$"
- pkill -f -n preview-tui-ext
+ pkill -P "$$" >/dev/null 2>&1
+ pkill -f -n preview-tui-ext >/dev/null 2>&1
echo > "$NNN_FIFO"
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
preview_fifo &
}
if [ "$TERMINAL" != "kitty" ] && [ "$PREVIEW_MODE" ] && exists ueberzug; then
trap 'ueberzug_refresh' WINCH
- trap 'rm "$FIFO_UEBERZUG"' INT HUP EXIT
+ trap 'rm "$FIFO_UEBERZUG" "$PAGERPID" "$GIFPID"' INT HUP EXIT
fi
preview_fifo() {
# shellcheck disable=SC2002
cat "$NNN_FIFO" |\
while read -r selection ; do
- [ "$gifpid" -ne 0 ] && kill "$gifpid"
+ kill "$(cat "$GIFPID" 2>/dev/null)" >/dev/null 2>&1
+ kill "$(cat "$PAGERPID" 2>/dev/null)" >/dev/null 2>&1
[ "$TERMINAL" != "kitty" ] && exists ueberzug && ueberzug_remove
preview_file "$selection"
done
[ "$TERMINAL" != "kitty" ] && exists ueberzug && rm "$FIFO_UEBERZUG"
+ rm "$PAGERPID" "$GIFPID" >/dev/null 2>&1
}
fi
if [ "$TERMINAL" != "kitty" ] && exists ueberzug; then
- FIFO_UEBERZUG="$TMPDIR/nnn-ueberzug-fifo.$$"
mkfifo "$FIFO_UEBERZUG"
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
fi