nnn: update plugins

This commit is contained in:
Hoang Nguyen 2021-04-23 01:56:19 +03:00
parent cec99f521a
commit 4f735592c6
No known key found for this signature in database
GPG Key ID: 813CF484F4993419
2 changed files with 59 additions and 18 deletions

View File

@ -76,16 +76,23 @@ IMAGE_CACHE_PATH="$(dirname "$1")"/.thumbs
FPATH="$1"
FNAME=$(basename "$1")
EDITOR="${EDITOR:-vi}"
EDITOR="${VISUAL:-${EDITOR:-vi}}"
PAGER="${PAGER:-less -R}"
ext="${FNAME##*.}"
if ! [ -z "$ext" ]; then
if [ -n "$ext" ]; then
ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
fi
is_mac() {
uname | grep -q "Darwin"
}
handle_pdf() {
if [ "$GUI" -ne 0 ] && which zathura >/dev/null 2>&1; then
zathura "${FPATH}" >/dev/null 2>&1 &
if [ "$GUI" -ne 0 ] && is_mac; then
nohup open "${FPATH}" >/dev/null 2>&1 &
exit 0
elif [ "$GUI" -ne 0 ] && which zathura >/dev/null 2>&1; then
nohup zathura "${FPATH}" >/dev/null 2>&1 &
exit 0
elif which pdftotext >/dev/null 2>&1; then
## Preview as text conversion
@ -120,11 +127,14 @@ handle_audio() {
}
handle_video() {
if [ "$GUI" -ne 0 ] && which smplayer >/dev/null 2>&1; then
smplayer "${FPATH}" >/dev/null 2>&1 &
if [ "$GUI" -ne 0 ] && is_mac; then
nohup open "${FPATH}" >/dev/null 2>&1 &
exit 0
elif [ "$GUI" -ne 0 ] && which smplayer >/dev/null 2>&1; then
nohup smplayer "${FPATH}" >/dev/null 2>&1 &
exit 0
elif [ "$GUI" -ne 0 ] && which mpv >/dev/null 2>&1; then
mpv "${FPATH}" >/dev/null 2>&1 &
nohup mpv "${FPATH}" >/dev/null 2>&1 &
exit 0
elif which ffmpegthumbnailer >/dev/null 2>&1; then
# Thumbnail
@ -257,7 +267,7 @@ abspath() {
listimages() {
find -L "$(dirname "$target")" -maxdepth 1 -type f -iregex \
'.*\(jpe?g\|bmp\|webp\|png\|gif\)$' -print0 | sort -z
'.*\(jpe?g\|bmp\|webp\|ico\|svg\|png\|gif\)$' -print0 | sort -z
}
load_dir() {
@ -265,7 +275,11 @@ load_dir() {
count="$(listimages | grep -a -m 1 -ZznF "$target" | cut -d: -f1)"
if [ -n "$count" ]; then
listimages | xargs -0 "$1" -n "$count" --
if [ "$GUI" -ne 0 ]; then
listimages | xargs -0 nohup "$1" -n "$count" --
else
listimages | xargs -0 "$1" -n "$count" --
fi
else
shift
"$1" -- "$@" # fallback
@ -294,7 +308,10 @@ handle_multimedia() {
## Image
image/*)
if [ "$GUI" -ne 0 ] && which imvr >/dev/null 2>&1; then
if [ "$GUI" -ne 0 ] && is_mac; then
nohup open "${FPATH}" >/dev/null 2>&1 &
exit 0
elif [ "$GUI" -ne 0 ] && which imvr >/dev/null 2>&1; then
load_dir imvr "${FPATH}" >/dev/null 2>&1 &
exit 0
elif [ "$GUI" -ne 0 ] && which sxiv >/dev/null 2>&1; then
@ -463,10 +480,10 @@ handle_mime() {
handle_fallback() {
if [ "$GUI" -ne 0 ] && which xdg-open >/dev/null 2>&1; then
xdg-open "${FPATH}" >/dev/null 2>&1 &
nohup xdg-open "${FPATH}" >/dev/null 2>&1 &
exit 0
elif [ "$GUI" -ne 0 ] && which open >/dev/null 2>&1; then
open "${FPATH}" >/dev/null 2>&1 &
nohup open "${FPATH}" >/dev/null 2>&1 &
exit 0
fi
@ -493,7 +510,7 @@ handle_blocked() {
esac
}
MIMETYPE="$( file --dereference --brief --mime-type -- "${FPATH}" )"
MIMETYPE="$( file -bL --mime-type -- "${FPATH}" )"
handle_extension
handle_multimedia "${MIMETYPE}"
handle_mime "${MIMETYPE}"

View File

@ -6,9 +6,10 @@
# For a more extended version of this script with additional optional dependencies, see preview-tui-ext.
#
# Dependencies:
# - Supports 3 independent methods to preview with:
# - Supports 4 independent methods to preview with:
# - tmux (>=3.0), or
# - kitty with allow_remote_control on, or
# - QuickLook on WSL (https://github.com/QL-Win/QuickLook)
# - $TERMINAL set to a terminal (it's xterm by default).
# - less or $PAGER
# - tree or exa or ls
@ -147,12 +148,18 @@ preview_file () {
cols=$(tput cols)
# Otherwise, falling back to the defaults.
if [ -d "$1" ]; then
if [ -n "$QUICKLOOK" ]; then
if exists QuickLook.exe && stat "$1" >/dev/null 2>&1; then
f="$(wslpath -w "$1" 2>&1)" && QuickLook.exe "$f" &
elif exists Bridge.exe && stat "$1" >/dev/null 2>&1; then
f="$(wslpath -w "$1" 2>&1)" && Bridge.exe "$f" &
fi
elif [ -d "$1" ]; then
cd "$1" || return
if exists tree; then
fifo_pager tree -L 1 --dirsfirst -F -C
fifo_pager tree -L 3 --dirsfirst -C -F --noreport -i
elif exists exa; then
fifo_pager exa -G --colour=always 2>/dev/null
exa -G --colour=always 2>/dev/null
else
fifo_pager ls --color=always
fi
@ -183,6 +190,10 @@ image_preview() {
# 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"
elif exists QuickLook.exe && stat "$3" >/dev/null 2>&1; then
f="$(wslpath -w "$3" 2>&1)" && QuickLook.exe "$f"
elif exists Bridge.exe && stat "$3" >/dev/null 2>&1; then
f="$(wslpath -w "$3" 2>&1)" && Bridge.exe "$f"
elif exists ueberzug; then
ueberzug_layer "$1" "$2" "$3"
elif exists catimg; then
@ -262,11 +273,22 @@ if [ "$PREVIEW_MODE" ]; then
exit 0
fi
if pgrep -f "cat $NNN_FIFO" >/dev/null; then
if exists QuickLook.exe && stat "$1" >/dev/null 2>&1; then
f="$(wslpath -w "$1" 2>&1)" && QuickLook.exe "$f" &
elif exists Bridge.exe && stat "$1" >/dev/null 2>&1; then
f="$(wslpath -w "$1" 2>&1)" && Bridge.exe "$f" &
fi
pkill -f "cat $NNN_FIO"
exit 0
fi
if [ "$TERMINAL" = "tmux" ]; then
# tmux splits are inverted
if [ "$SPLIT" = "v" ]; then SPLIT="h"; else SPLIT="v"; fi
tmux split-window -e "NNN_FIFO=$NNN_FIFO" -e "PREVIEW_MODE=1" -d"$SPLIT" "$0" "$1"
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" \
-d"$SPLIT" "$0" "$1"
elif [ "$TERMINAL" = "kitty" ]; then
# Setting the layout for the new window. It will be restored after the
# script ends.
@ -281,6 +303,8 @@ elif [ "$TERMINAL" = "kitty" ]; then
--env "USE_SCOPE=$USE_SCOPE" --env "SPLIT=$SPLIT" \
--env "USE_PISTOL=$USE_PISTOL" \
--location "${SPLIT}split" "$0" "$1" >/dev/null
elif exists QuickLook.exe || exists Bridge.exe; then
QUICKLOOK=1 PREVIEW_MODE=1 "$0" "$1" >/dev/null &
else
PREVIEW_MODE=1 $TERMINAL -e "$0" "$1" &
fi