From adf381acee7a341c07ecd8514f1fc526bbb1abfd Mon Sep 17 00:00:00 2001 From: lvgx Date: Fri, 22 May 2020 04:48:00 +0200 Subject: Change binary file detection in preview-tui/kitty (#587) --- plugins/preview-kitty | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'plugins/preview-kitty') diff --git a/plugins/preview-kitty b/plugins/preview-kitty index 4bff54d..8ebf86f 100755 --- a/plugins/preview-kitty +++ b/plugins/preview-kitty @@ -31,22 +31,23 @@ preview_file () { 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 - elif [ "${mime%%/*}" = "text" ] ; then - # Print file head - bat --terminal-width="$cols" --paging=never --decorations=always \ - --color=always "$1" 2>/dev/null || cat elif [ "${mime%%/*}" = "image" ] ; then kitty +kitten icat --silent --transfer-mode=stream --stdin=no "$1" - else - # Binary file + 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" + else + # Text file: print colored file content + bat --terminal-width="$cols" --paging=never --decorations=always \ + --color=always "$1" 2>/dev/null || cat fi | head -n $lines } -- cgit v1.2.3-70-g09d2