]> Sergey Matveev's repositories - nnn.git/commitdiff
preview-tui: directly call $PAGER on text files (#599)
authorlvgx <l@vgx.fr>
Wed, 27 May 2020 23:34:53 +0000 (01:34 +0200)
committerGitHub <noreply@github.com>
Wed, 27 May 2020 23:34:53 +0000 (05:04 +0530)
plugins/preview-tui

index b156cacf3d105eb411527b2e233c554f62701d2c..7872b07e17e6b930c2b3dec99779eb506a20b082 100755 (executable)
@@ -25,35 +25,36 @@ TERMINAL="${TERMINAL:-xterm}"
 PAGER="${PAGER:-less}"
 
 preview_file () {
-    kill %- %+ 2>/dev/null
+    kill "$(jobs -p)" 2>/dev/null
     clear
 
-    # prevent shell pipe reuse
-    tmpfifopath="${TMPDIR:-/tmp}/nnn-preview-tui-fifo.$$"
-    mkfifo "$tmpfifopath" || return
-
     encoding="$(file -b --mime-encoding "$1")"
 
-    $PAGER < "$tmpfifopath" &
+    if [ -d "$1" ]; then
+        # Print directory tree
+
+        cd "$1" || return
 
-    (
-        exec > "$tmpfifopath"
+        # we use a FIFO to access less PID
+        tmpfifopath="${TMPDIR:-/tmp}/nnn-preview-tui-fifo.$$"
+        mkfifo "$tmpfifopath" || return
 
-        if [ -d "$1" ]; then
-            # Print directory tree
-            cd "$1" && tree
-        elif [ "$encoding" = "binary" ] ; then
-            # Binary file: just print filetype info
-            echo "-------- Binary file --------"
-            file -b "$1"
-        else
-            # Text file:
-            cat "$1"
-        fi &
+        $PAGER < "$tmpfifopath" &
 
-    )
+        (
+            exec > "$tmpfifopath"
+            tree&
+        )
 
-    rm "$tmpfifopath"
+        rm "$tmpfifopath"
+    elif [ "$encoding" = "binary" ] ; then
+        # Binary file: just print filetype info
+        echo "-------- Binary file --------"
+        file -b "$1"
+    else
+        # Text file:
+        $PAGER "$1" &
+    fi
 }
 
 if [ "$PREVIEW_MODE" ] ; then