]> Sergey Matveev's repositories - nnn.git/commitdiff
More minimal bat previews, minor improvements to fzplug (#1004)
authorKabouik <7107523+Kabouik@users.noreply.github.com>
Fri, 14 May 2021 14:29:43 +0000 (14:29 +0000)
committerGitHub <noreply@github.com>
Fri, 14 May 2021 14:29:43 +0000 (19:59 +0530)
* More minimal bat previews, minor improvements to fzplug

* Use BAT_STYLE if set, better fzplug formatting

* Fix linebreak in single quotes

* Fix line numbers in comments

* Readability and shellcheck warning

* Fix line numbers in comments

* Breaking typo

* Pre-existing BAT_STYLE would not be honored in tmux

plugins/fzplug
plugins/preview-tui
plugins/preview-tui-ext

index b945e0c69eff9bfacd71919f3b49e305d002cd4d..e7993455066da95c3638b7bddd0bf5c353f09c0b 100755 (executable)
@@ -2,9 +2,9 @@
 
 # Description: Fuzzy find and execute nnn plugins (and, optionally, custom scripts located elsewhere).
 # Description and details of plugins can be previewed from the fzf interface. Use `?` to toggle preview
-# pane on and off.
+# pane on and off, ^Up/^Dn to scroll.
 #
-# For better compatibility with as many nnn plugins as possible, fzfplug will first execute
+# For better compatibility with as many nnn plugins as possible, fzplug will first execute
 # the chosen script on the file hovered in nnn, and upon failure, try to run it with no target
 # (i.e on an active selection, if present).
 #
@@ -15,7 +15,7 @@
 # Optional scripts sources
 # Leave blank or fill with the absolute path of a folder containing executable scripts other than nnn plugins
 # (e.g., "$HOME/.local/share/nautilus/scripts", since there are numerous Nautilus script git repositories).
-# Add extra variables if need be, but be sure to call them in the find command below at lines 28:49 and 30:49.
+# Add extra variables if need be, but be sure to call them in the find command below at lines 27 and 33.
 #CUSTOMDIR1="$HOME/.local/share/nautilus/scripts"
 CUSTOMDIR1=""
 CUSTOMDIR2=""
@@ -24,9 +24,18 @@ nnnpluginsdir="$HOME/.config/nnn/plugins"
 
 # Preview with bat if installed
 if [ -z "$(command -v bat)" ]; then
-    plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" -maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview 'cat {}' --preview-window right:66% --delimiter / --with-nth -1 --bind="?:toggle-preview")
+    plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" \
+        -maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview \
+        "cat {}" \
+        --preview-window right:66%:wrap --delimiter / --with-nth -1 \
+        --bind="?:toggle-preview")
 else
-    plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" -maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview 'bat --color=always --style=grid {}' --preview-window right:66% --delimiter / --with-nth -1 --bind="?:toggle-preview")
+    plugin=$(find "$nnnpluginsdir" "$CUSTOMDIR1" "$CUSTOMDIR2" \
+        -maxdepth 3 -perm -111 -type f 2>/dev/null | fzf --ansi --preview \
+        "bat --terminal-width='$(tput cols)' --decorations=always --color=always \
+              --style='${BAT_STYLE:-header,numbers}' {}" \
+        --preview-window right:66% --delimiter / --with-nth -1 \
+        --bind="?:toggle-preview")
 fi
 
 # Try running the script on the hovered file, and abort if no plugin was selected (ESC or ^C pressed),
index c0b055a1e56f45748a9fe03e6a241861e82226bf..2bd05ef796435d42b16f8263e0314d9b73e7d962 100755 (executable)
@@ -97,7 +97,8 @@ startpreview() {
 
         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 "PAGERPID=$PAGERPID" -e "IMGPID=$IMGPID" -e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" \
+            -e "BAT_STYLE=${BAT_STYLE:-numbers}" -e "PAGERPID=$PAGERPID" \
+            -e "IMGPID=$IMGPID" -e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" \
             -e "FIFO_UEBERZUG=$FIFO_UEBERZUG" -e "QLPATH=$QLPATH" -d"$SPLIT" "$0" "$1"
     elif [ "$TERMINAL" = "kitty" ]; then
         # Setting the layout for the new window. It will be restored after the
@@ -111,8 +112,8 @@ startpreview() {
             --cwd "$PWD" --env "PATH=$PATH" --env "NNN_FIFO=$NNN_FIFO" \
             --env "PREVIEW_MODE=1" --env "PAGER=$PAGER" --env "TMPDIR=$TMPDIR" \
             --env "USE_SCOPE=$USE_SCOPE" --env "SPLIT=$SPLIT" --env "TERMINAL=$TERMINAL"\
-            --env "USE_PISTOL=$USE_PISTOL" --env "PAGERPID=$PAGERPID" \
-            --env "IMGPID=$IMGPID" --env "FIFO_UEBERZUG=$FIFO_UEBERZUG" \
+            --env "USE_PISTOL=$USE_PISTOL" --env "BAT_STYLE=${BAT_STYLE:-numbers}" \
+            --env "PAGERPID=$PAGERPID" --env "GIFPID=$GIFPID" --env "FIFO_UEBERZUG=$FIFO_UEBERZUG" \
             --env "CURSEL=$CURSEL" --location "${SPLIT}split" "$0" "$1" >/dev/null
     elif [ -n "$2" ]; then
         QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" >/dev/null &
@@ -156,7 +157,8 @@ fifo_pager() {
         exec > "$tmpfifopath"
         if [ "$cmd" = "pager" ]; then
             if exists bat; then
-                bat --terminal-width="$(tput cols)" --paging=never --decorations=always --color=always "$@" 2>/dev/null &
+                bat --terminal-width="$(tput cols)" --decorations=always --color=always \
+                    --paging=never --style="${BAT_STYLE:-numbers}" "$@" 2>/dev/null &
             else
                 $PAGER "$@" &
             fi
index e50b3e416e52eb88771b4f8f1143885b27c22b32..1d05c784a5ea0d4776105814b565eaefdd5d791d 100755 (executable)
@@ -113,7 +113,8 @@ startpreview() {
 
         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 "PAGERPID=$PAGERPID" -e "IMGPID=$IMGPID" -e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" \
+            -e "BAT_STYLE=${BAT_STYLE:-numbers}" -e "PAGERPID=$PAGERPID" \
+            -e "IMGPID=$IMGPID" -e "CURSEL=$CURSEL" -e "TMPDIR=$TMPDIR" \
             -e "ICONLOOKUP=$ICONLOOKUP" -e "NNN_PREVIEWDIR=$NNN_PREVIEWDIR" \
             -e "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" -e "NNN_PREVIEWHEIGHT=$NNN_PREVIEWHEIGHT" \
             -e "FIFO_UEBERZUG=$FIFO_UEBERZUG" -e "QLPATH=$2" -d"$SPLIT" "$0" "$1"
@@ -129,8 +130,8 @@ startpreview() {
             --cwd "$PWD" --env "PATH=$PATH" --env "NNN_FIFO=$NNN_FIFO" \
             --env "PREVIEW_MODE=1" --env "PAGER=$PAGER" --env "TMPDIR=$TMPDIR" \
             --env "USE_SCOPE=$USE_SCOPE" --env "SPLIT=$SPLIT" --env "TERMINAL=$TERMINAL"\
-            --env "USE_PISTOL=$USE_PISTOL" --env "PAGERPID=$PAGERPID"  \
-            --env "IMGPID=$IMGPID" --env "FIFO_UEBERZUG=$FIFO_UEBERZUG" \
+            --env "USE_PISTOL=$USE_PISTOL" --env "BAT_STYLE=${BAT_STYLE:-numbers}" \
+            --env "PAGERPID=$PAGERPID" --env "GIFPID=$GIFPID" --env "FIFO_UEBERZUG=$FIFO_UEBERZUG" \
             --env "ICONLOOKUP=$ICONLOOKUP" --env "NNN_PREVIEWDIR=$NNN_PREVIEWDIR" \
             --env "NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH" --env "NNN_PREVIEWHEIGHT=$NNN_PREVIEWHEIGHT" \
             --env "CURSEL=$CURSEL" --location "${SPLIT}split" "$0" "$1" >/dev/null
@@ -176,7 +177,8 @@ fifo_pager() {
         exec > "$tmpfifopath"
         if [ "$cmd" = "pager" ]; then
             if exists bat; then
-                bat --terminal-width="$(tput cols)" --paging=never --decorations=always --color=always "$@" 2>/dev/null &
+                bat --terminal-width="$(tput cols)" --decorations=always --color=always \
+                    --paging=never --style="${BAT_STYLE:-numbers}" "$@" 2>/dev/null &
             else
                 $PAGER "$@" &
             fi