"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "plugins/preview-tui" between
nnn-v4.3.tar.gz and nnn-v4.4.tar.gz

About: nnn is a full-featured terminal file manager.

preview-tui  (nnn-v4.3):preview-tui  (nnn-v4.4)
skipping to change at line 70 skipping to change at line 70
# #
# Tmux and kitty users can configure $SPLIT to either "h" or "v" to set a # Tmux and kitty users can configure $SPLIT to either "h" or "v" to set a
# 'h'orizontal split or a 'v'ertical split (as in, the line that splits the # 'h'orizontal split or a 'v'ertical split (as in, the line that splits the
# windows will be horizontal or vertical). # windows will be horizontal or vertical).
# #
# Kitty users need `allow_remote_control` set to `yes`, and `listen_on` set # Kitty users need `allow_remote_control` set to `yes`, and `listen_on` set
# to e.g. "unix:$TMPDIR/kitty". To customize the window split, `enabled_layout s` # to e.g. "unix:$TMPDIR/kitty". To customize the window split, `enabled_layout s`
# has to be set to `all` or `splits` (the former is the default value). # has to be set to `all` or `splits` (the former is the default value).
# This terminal is also able to show images without extra dependencies. # This terminal is also able to show images without extra dependencies.
# #
# Iterm2 users are recommended to use viu to view images without getting pixel
ated.
#
# Shell: POSIX compliant # Shell: POSIX compliant
# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero, Lu uk van Baal # Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero, Lu uk 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}" BAT_STYLE="${BAT_STYLE:-numbers}"
BAT_THEME="${BAT_THEME:-ansi}" BAT_THEME="${BAT_THEME:-ansi}"
# 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#*.}" NNN_PARENT="${NNN_FIFO#*.}"
[ "$NNN_PARENT" -eq "$NNN_PARENT" ] 2>/dev/null || NNN_PARENT=""
FIFOPID="$TMPDIR/nnn-preview-tui-fifopid.$NNN_PARENT" FIFOPID="$TMPDIR/nnn-preview-tui-fifopid.$NNN_PARENT"
PREVIEWPID="$TMPDIR/nnn-preview-tui-pagerpid.$NNN_PARENT" PREVIEWPID="$TMPDIR/nnn-preview-tui-pagerpid.$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"
start_preview() { start_preview() {
[ "$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
TERMINAL=tmux TERMINAL=tmux
elif [ -n "$KITTY_LISTEN_ON" ]; then elif [ -n "$KITTY_LISTEN_ON" ]; then
TERMINAL=kitty TERMINAL=kitty
elif [ -z "$TERMINAL" ] && [ "$TERM_PROGRAM" = "iTerm.app" ]; then
TERMINAL=iterm
else else
TERMINAL="${TERMINAL:-xterm}" TERMINAL="${TERMINAL:-xterm}"
fi fi
if [ -z "$SPLIT" ] && [ $(($(tput lines) * 2)) -gt "$(tput cols)" ]; then if [ -z "$SPLIT" ] && [ $(($(tput lines <"$TTY") * 2)) -gt "$(tput cols <"$T TY")" ]; then
SPLIT='h' SPLIT='h'
elif [ "$SPLIT" != 'h' ]; then elif [ "$SPLIT" != 'h' ]; then
SPLIT='v' SPLIT='v'
fi fi
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" \ tmux split-window -e "NNN_FIFO=$NNN_FIFO" -e "PREVIEW_MODE=1" -e TTY ="$TTY" \
-e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" -e "FIFOPID=$FIFOPID" \ -e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" -e "FIFOPID=$FIFOPID" \
-e "BAT_STYLE=$BAT_STYLE" -e "BAT_THEME=$BAT_THEME" -e "PREVIEWP ID=$PREVIEWPID" \ -e "BAT_STYLE=$BAT_STYLE" -e "BAT_THEME=$BAT_THEME" -e "PREVIEWP ID=$PREVIEWPID" \
-e "PAGER=$PAGER" -e "ICONLOOKUP=$ICONLOOKUP" -e "NNN_PREVIEWWID TH=$NNN_PREVIEWWIDTH" \ -e "PAGER=$PAGER" -e "ICONLOOKUP=$ICONLOOKUP" -e "NNN_PREVIEWWID TH=$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 "NNN_PREVIEWDIR=$NNN_PREVIEWDIR" -e "NNN_PREVIEWHEIGHT=$NNN_P REVIEWHEIGHT" \ -e "NNN_PREVIEWDIR=$NNN_PREVIEWDIR" -e "NNN_PREVIEWHEIGHT=$NNN_P REVIEWHEIGHT" \
-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 afte r the script ends. kitty) # Setting the layout for the new window. It will be restored afte r the script ends.
kitty @ goto-layout splits kitty @ goto-layout splits
# Trying to use kitty's integrated window management as the split wi ndow. All # Trying to use kitty's integrated window management as the split wi ndow. All
# environmental variables that will be used in the new window must b e explicitly passed. # environmental variables that will be used in the new window must b e 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 "PREVIEW_MODE=1" --env "PAGER=$PAGER" --env "TMPDIR=$TMPDI R" \ --env "PREVIEW_MODE=1" --env "PAGER=$PAGER" --env "TMPDIR=$TMPDI R" \
--env "USE_SCOPE=$USE_SCOPE" --env "SPLIT=$SPLIT" --env "TERMINA L=$TERMINAL"\ --env "USE_SCOPE=$USE_SCOPE" --env "SPLIT=$SPLIT" --env "TERMINA L=$TERMINAL"\
--env "PREVIEWPID=$PREVIEWPID" --env "FIFO_UEBERZUG=$FIFO_UEBERZ UG" \ --env "PREVIEWPID=$PREVIEWPID" --env "FIFO_UEBERZUG=$FIFO_UEBERZ UG" \
--env "ICONLOOKUP=$ICONLOOKUP" --env "NNN_PREVIEWHEIGHT=$NNN_PRE VIEWHEIGHT" \ --env "ICONLOOKUP=$ICONLOOKUP" --env "NNN_PREVIEWHEIGHT=$NNN_PRE VIEWHEIGHT" \
--env "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" --env "NNN_PREVIEWDIR =$NNN_PREVIEWDIR" \ --env "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" --env "NNN_PREVIEWDIR =$NNN_PREVIEWDIR" \
--env "USE_PISTOL=$USE_PISTOL" --env "BAT_STYLE=$BAT_STYLE" \ --env "USE_PISTOL=$USE_PISTOL" --env "BAT_STYLE=$BAT_STYLE" \
--env "BAT_THEME=$BAT_THEME" --env "FIFOPID=$FIFOPID" \ --env "BAT_THEME=$BAT_THEME" --env "FIFOPID=$FIFOPID" --env TTY= "$TTY" \
--env "CURSEL=$CURSEL" --location "${SPLIT}split" "$0" "$1" ;; --env "CURSEL=$CURSEL" --location "${SPLIT}split" "$0" "$1" ;;
iterm)
command="$SHELL -c 'cd $PWD; \
PATH=\\\"$PATH\\\" NNN_FIFO=\\\"$NNN_FIFO\\\" PREVIEW_MODE=1 PAG
ER=\\\"$PAGER\\\" \
USE_SCOPE=\\\"$USE_SCOPE\\\" SPLIT=\\\"$SPLIT\\\" TERMINAL=\\\"$
TERMINAL\\\" \
PREVIEWPID=\\\"$PREVIEWPID\\\" CURSEL=\\\"$CURSEL\\\" TMPDIR=\\\
"$TMPDIR\\\" \
ICONLOOKUP=\\\"$ICONLOOKUP\\\" NNN_PREVIEWHEIGHT=\\\"$NNN_PREVIE
WHEIGHT\\\" \
NNN_PREVIEWWIDTH=\\\"$NNN_PREVIEWWIDTH\\\" NNN_PREVIEWDIR=\\\"$N
NN_PREVIEWDIR\\\" \
USE_PISTOL=\\\"$USE_PISTOL\\\" BAT_STYLE=\\\"$BAT_STYLE\\\" TTY=
\\\"$TTY\\\" \
BAT_THEME=\\\"$BAT_THEME\\\" FIFOPID=\\\"$FIFOPID\\\" \\\"$0\\\"
\\\"$1\\\"'"
if [ "$SPLIT" = "h" ]; then split="horizontally"; else split="vertic
ally"; fi
osascript <<-EOF
tell application "iTerm"
tell current session of current window
split $split with default profile command "$command"
end tell
end tell
EOF
;;
*) 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
PREVIEWPID="$PREVIEWPID" CURSEL="$CURSEL" PREVIEW_MODE=1 \ PREVIEWPID="$PREVIEWPID" CURSEL="$CURSEL" PREVIEW_MODE=1 TTY="$T TY" \
FIFOPID="$FIFOPID" FIFO_UEBERZUG="$FIFO_UEBERZUG" $TERMINAL -e "$0" "$1" & FIFOPID="$FIFOPID" FIFO_UEBERZUG="$FIFO_UEBERZUG" $TERMINAL -e "$0" "$1" &
fi ;; fi ;;
esac esac
} >/dev/null 2>&1 } >/dev/null 2>&1
toggle_preview() { 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"
skipping to change at line 180 skipping to change at line 203
tmpfifopath="$TMPDIR/nnn-preview-tui-fifo.$$" tmpfifopath="$TMPDIR/nnn-preview-tui-fifo.$$"
mkfifo "$tmpfifopath" || return mkfifo "$tmpfifopath" || return
$PAGER < "$tmpfifopath" & $PAGER < "$tmpfifopath" &
printf "%s" "$!" > "$PREVIEWPID" printf "%s" "$!" > "$PREVIEWPID"
( (
exec > "$tmpfifopath" exec > "$tmpfifopath"
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 <"$TTY")" --decorations=always --color=always \
--paging=never --style="$BAT_STYLE" --theme="$BAT_THEME" "$@ " & --paging=never --style="$BAT_STYLE" --theme="$BAT_THEME" "$@ " &
else else
$PAGER "$@" & $PAGER "$@" &
fi fi
else else
"$cmd" "$@" & "$cmd" "$@" &
fi fi
) )
rm "$tmpfifopath" rm "$tmpfifopath"
skipping to change at line 210 skipping to change at line 233
fi fi
} 2>/dev/null } 2>/dev/null
handle_mime() { handle_mime() {
case "$2" in case "$2" in
image/jpeg) image_preview "$cols" "$lines" "$1" ;; image/jpeg) image_preview "$cols" "$lines" "$1" ;;
image/gif) generate_preview "$cols" "$lines" "$1" "gif" ;; image/gif) generate_preview "$cols" "$lines" "$1" "gif" ;;
image/*) generate_preview "$cols" "$lines" "$1" "image" ;; image/*) generate_preview "$cols" "$lines" "$1" "image" ;;
video/*) generate_preview "$cols" "$lines" "$1" "video" ;; video/*) generate_preview "$cols" "$lines" "$1" "video" ;;
audio/*) generate_preview "$cols" "$lines" "$1" "audio" ;; audio/*) generate_preview "$cols" "$lines" "$1" "audio" ;;
application/font*|application/*opentype) generate_preview "$cols" "$line s" "$1" "font" ;; application/font*|application/*opentype|font/*) generate_preview "$cols" "$lines" "$1" "font" ;;
*/*office*|*/*document*) generate_preview "$cols" "$lines" "$1" "office" ;; */*office*|*/*document*) generate_preview "$cols" "$lines" "$1" "office" ;;
application/zip) fifo_pager unzip -l "$1" ;; application/zip) fifo_pager unzip -l "$1" ;;
text/troff) text/troff)
if exists man; then if exists man; then
fifo_pager man -Pcat -l "$1" fifo_pager man -Pcat -l "$1"
else else
fifo_pager pager "$1" fifo_pager pager "$1"
fi ;; fi ;;
*) handle_ext "$1" "$3" "$4" ;; *) handle_ext "$1" "$3" "$4" ;;
esac esac
skipping to change at line 285 skipping to change at line 308
if [ -n "$QUICKLOOK" ]; then if [ -n "$QUICKLOOK" ]; then
stat "$1" && f="$(wslpath -w "$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 extensi on in lowercase. # Detecting the exact type of the file: the encoding, mime type, and extensi on 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##*.}"
[ -n "$ext" ] && ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')" [ -n "$ext" ] && ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
lines=$(tput lines) lines=$(tput lines <"$TTY")
cols=$(tput cols) cols=$(tput cols <"$TTY")
# Otherwise, falling back to the defaults. # Otherwise, falling back to the defaults.
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" = v ] && BSTR="\n" [ "$SPLIT" = v ] && BSTR="\n"
# shellcheck disable=SC2012 # shellcheck disable=SC2012
ls -F --group-directories-first | head -n "$((lines - 3))" | "$(dirn ame "$0")"/.iconlookup -l "$cols" -B "$BSTR" -b " " ls -F --group-directories-first | head -n "$((lines - 3))" | "$(dirn ame "$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
skipping to change at line 388 skipping to change at line 411
} }
winch_handler() { winch_handler() {
clear clear
kill "$(cat "$PREVIEWPID")" kill "$(cat "$PREVIEWPID")"
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 &
fi fi
preview_file "$(cat "$CURSEL")" preview_file "$(cat "$CURSEL")"
if ! kill -0 "$NNN_PARENT" || ! pgrep nnn >/dev/null; then
pkill -P "$$"
fi
} 2>/dev/null } 2>/dev/null
preview_fifo() { preview_fifo() {
while read -r selection; do while read -r selection; do
if [ -n "$selection" ]; then if [ -n "$selection" ]; then
kill "$(cat "$PREVIEWPID")" kill "$(cat "$PREVIEWPID")"
[ -p "$FIFO_UEBERZUG" ] && ueberzug_remove [ -p "$FIFO_UEBERZUG" ] && ueberzug_remove
[ "$selection" = "close" ] && sleep 0.15 && break [ "$selection" = "close" ] && sleep 0.15 && pkill -P "$$" && exit
preview_file "$selection" preview_file "$selection"
printf "%s" "$selection" > "$CURSEL" printf "%s" "$selection" > "$CURSEL"
fi fi
done < "$NNN_FIFO" done < "$NNN_FIFO"
sleep 0.1 # make sure potential preview by winch_handler is killed
pkill -P "$$" pkill -P "$$"
} 2>/dev/null } 2>/dev/null
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"
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json & tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser json &
fi fi
preview_file "$PWD/$1" preview_file "$PWD/$1"
skipping to change at line 429 skipping to change at line 450
else else
if [ ! -r "$NNN_FIFO" ]; then if [ ! -r "$NNN_FIFO" ]; then
clear clear
printf "No FIFO available! (\$NNN_FIFO='%s')\nPlease read Usage in previ ew-tui." "$NNN_FIFO" printf "No FIFO available! (\$NNN_FIFO='%s')\nPlease read Usage in previ ew-tui." "$NNN_FIFO"
cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg" cfg=$(stty -g); stty raw -echo; head -c 1; stty "$cfg"
elif [ "$KITTY_WINDOW_ID" ] && [ -z "$TMUX" ] && [ -z "$KITTY_LISTEN_ON" ]; then elif [ "$KITTY_WINDOW_ID" ] && [ -z "$TMUX" ] && [ -z "$KITTY_LISTEN_ON" ]; then
clear clear
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
toggle_preview "$1" & TTY="$(tty)"
TTY="$TTY" toggle_preview "$1" &
fi fi
fi fi
 End of changes. 15 change blocks. 
13 lines changed or deleted 44 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)