diff options
author | lvgx <l@vgx.fr> | 2020-05-28 01:34:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-28 05:04:53 +0530 |
commit | 135821aa521cd3120c18681d57785ebefc78fe81 (patch) | |
tree | 20399e69b2f415d3e207b768de5f9ea18d0676e0 /plugins/preview-tui | |
parent | bbcd89c8d6e1d81ea2e128468e98b3c42dca7d3d (diff) | |
download | nnn-135821aa521cd3120c18681d57785ebefc78fe81.tar.gz |
preview-tui: directly call $PAGER on text files (#599)
Diffstat (limited to 'plugins/preview-tui')
-rwxr-xr-x | plugins/preview-tui | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/plugins/preview-tui b/plugins/preview-tui index b156cac..7872b07 100755 --- a/plugins/preview-tui +++ b/plugins/preview-tui @@ -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 |