diff options
| author | 2020-06-09 03:09:35 +0200 | |
|---|---|---|
| committer | 2020-06-09 07:16:35 +0530 | |
| commit | a47d190654204b8a46c7be9cc641382e597c25ad (patch) | |
| tree | 3a9db65f80994853a3c924f7e2736eccc4505d2e /plugins/preview-kitty | |
| parent | c5f0a25e7e8bf09df7f495af907f8a7d4f967cbd (diff) | |
| download | nnn-a47d190654204b8a46c7be9cc641382e597c25ad.tar.gz | |
Unified preview-tui and preview-kitty scripts (#634)
* Unified preview-tui and preview-kitty
* Remove preview-kitty
* No need to set $TERMINAL
* fix undeclared variable
* Integrated support for scope.sh
* Review fixes
* allow_remote_control must be enabled on kitty
* Documentation, kitty splits and images fallback
* fix restoring kitty layout
Diffstat (limited to 'plugins/preview-kitty')
| -rwxr-xr-x | plugins/preview-kitty | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/plugins/preview-kitty b/plugins/preview-kitty deleted file mode 100755 index af51cee..0000000 --- a/plugins/preview-kitty +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env sh - -# Description: File previewer for kitty term using NNN_FIFO -# -# Dependencies: -# - kitty (https://sw.kovidgoyal.net/kitty/) with allow_remote_control on -# - file -# - exa (https://github.com/ogham/exa) (fallback: ls) -# - bat (https://github.com/sharkdp/bat) (fallback: cat) -# - mediainfo (fallback: file) -# -# Usage: -# This plugin only works in kitty (https://sw.kovidgoyal.net/kitty/), -# and with kitty's 'allow_remote_control' option turned on. -# You need to set a NNN_FIFO path and set a key for the plugin, -# then start `nnn`: -# -# $ NNN_FIFO=/tmp/nnn.fifo nnn -# -# Then in `nnn`, launch the `preview-kitty` plugin. -# -# If you provide the same NNN_FIFO to all nnn instances, there will be a -# single common preview window. If you provide different FIFO path, they -# will be independent. -# -# Shell: POSIX compliant -# Authors: Léo Villeveygoux - -preview_file () { - kill %% 2>/dev/null - clear - lines=$(($(tput lines)-1)) - cols=$(tput cols) - mime="$(file -b --mime-type "$1")" - encoding="$(file -b --mime-encoding "$1")" - - if [ -d "$1" ]; then - # Print directory tree - # shellcheck disable=SC2015 - cd "$1" && \ - (COLUMNS=$cols exa -G --colour=always 2>/dev/null ||\ - ls --color=alway) | head -n $lines & - # remove second clause to preview SVG files (but this is slow) - elif [ "${mime%%/*}" = "image" ] && [ "$encoding" = "binary" ] ; then - kitty +kitten icat --silent --transfer-mode=stream --stdin=no "$1" & - elif [ "$encoding" = "binary" ] ; then - # Binary file: show file info - printf -- "-------- \033[1;31mBinary file\033[0m --------\n" - (mediainfo "$1" 2>/dev/null || file -b "$1") | head -n $((lines - 1)) & - else - # Text file: print colored file content - (bat --terminal-width="$cols" --paging=never --decorations=always \ - --color=always "$1" 2>/dev/null || cat) | head -n $lines & - fi -} - -if [ "$PREVIEW_MODE" ] ; then - if [ ! -r "$NNN_FIFO" ] ; then - echo "No FIFO available! (\$NNN_FIFO='$NNN_FIFO')" >&2 - read -r - exit 1 - fi - - preview_file "$1" - - # use cat instead of 'exec <' to avoid issues with dash shell - # shellcheck disable=SC2002 - cat "$NNN_FIFO" |\ - while read -r selection ; do - preview_file "$selection" - done - exit 0 -fi - -kitty @ launch --no-response --title "nnn preview" --keep-focus \ - --cwd="$PWD" --env "NNN_FIFO=$NNN_FIFO" --env "PREVIEW_MODE=1" \ - "$0" "$1" > /dev/null |