]> Sergey Matveev's repositories - nnn.git/commitdiff
Preview-tui support windows terminal split
authorLuuk van Baal <luukvbaal@gmail.com>
Mon, 17 Jan 2022 13:20:27 +0000 (14:20 +0100)
committerLuuk van Baal <luukvbaal@gmail.com>
Mon, 17 Jan 2022 13:20:27 +0000 (14:20 +0100)
Co-authored-by: WanderLanz
plugins/preview-tui

index 81f9f4fbdb50ae4e834f9b165ab4c079b09c2b49..ebca5aed313e351345dc65c3a733bfa6937ee741 100755 (executable)
@@ -5,10 +5,11 @@
 # Note: This plugin needs a "NNN_FIFO" to work. See man.
 #
 # Dependencies:
-#   - Supports 4 independent methods to preview with:
+#   - Supports 5 independent methods to preview with:
 #       - tmux (>=3.0), or
 #       - kitty with allow_remote_control and listen_on set in kitty.conf, or
-#       - QuickLook on WSL (https://github.com/QL-Win/QuickLook)
+#       - QuickLook on WSL (https://github.com/QL-Win/QuickLook), or
+#       - Windows Terminal (https://github.com/Microsoft/Terminal | https://aka.ms/terminal) with WSL, or
 #       - $TERMINAL set to a terminal (it's xterm by default).
 #   - less or $PAGER
 #   - tree or exa or ls
 #
 #   Iterm2 users are recommended to use viu to view images without getting pixelated.
 #
+#   Windows Terminal users can set "Profile termination behavior" under "Profile > Advanced" settings
+#   to automaticaly close pane on quit when exit code is 0.
+#
 # Shell: POSIX compliant
-# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero, Luuk van Baal
+# Authors: Todd Yamakawa, Léo Villeveygoux, @Recidiviste, Mario Ortiz Manero, Luuk van Baal, @WanderLanz
 
 #SPLIT="$SPLIT"  # you can set a permanent split here
 #TERMINAL="$TERMINAL"  # same goes for the terminal
@@ -101,6 +105,8 @@ start_preview() {
         TERMINAL=kitty
     elif [ -z "$TERMINAL" ] && [ "$TERM_PROGRAM" = "iTerm.app" ]; then
         TERMINAL=iterm
+    elif [ -n "$WT_SESSION" ]; then
+        TERMINAL=winterm
     else
         TERMINAL="${TERMINAL:-xterm}"
     fi
@@ -153,6 +159,16 @@ start_preview() {
             end tell
 EOF
             ;;
+        winterm)
+            if [ "$SPLIT" = "h" ]; then split="H"; else split="V"; fi
+            cmd.exe /c wt -w 0 sp -$split bash -c "cd $PWD \; PATH='$PATH' NNN_FIFO=$NNN_FIFO \
+                PREVIEW_MODE=1 TTY=$TTY CURSEL=$CURSEL TMPDIR=$TMPDIR FIFOPID=$FIFOPID \
+                BAT_STYLE=$BAT_STYLE BAT_THEME=$BAT_THEME PREVIEWPID=$PREVIEWPID \
+                PAGER='$PAGER' ICONLOOKUP=$ICONLOOKUP NNN_PREVIEWWIDTH=$NNN_PREVIEWWIDTH \
+                USE_SCOPE=$USE_SCOPE SPLIT=$SPLIT USE_PISTOL=$USE_PISTOL \
+                NNN_PREVIEWDIR=$NNN_PREVIEWDIR NNN_PREVIEWHEIGHT=$NNN_PREVIEWHEIGHT \
+                FIFO_UEBERZUG=$FIFO_UEBERZUG QLPATH=$2 $0 $1" \; -w 0 mf previous
+            ;;
         *)  if [ -n "$2" ]; then
                 QUICKLOOK=1 QLPATH="$2" PREVIEW_MODE=1 "$0" "$1" &
             else
@@ -441,6 +457,7 @@ if [ "$PREVIEW_MODE" ]; then
     trap 'winch_handler; wait' WINCH
     trap 'rm "$PREVIEWPID" "$CURSEL" "$FIFO_UEBERZUG" "$FIFOPID" 2>/dev/null' INT HUP EXIT
     wait "$!" 2>/dev/null
+    exit 0
 else
     if [ ! -r "$NNN_FIFO" ]; then
         clear