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-tui | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'plugins/preview-tui') diff --git a/plugins/preview-tui b/plugins/preview-tui index 3ebf195..5e1fd67 100755 --- a/plugins/preview-tui +++ b/plugins/preview-tui @@ -27,18 +27,18 @@ preview_file () { 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 cd "$1" && tree | head -n $lines | cut -c 1-"$cols" - elif [ "${mime%%/*}" = "text" ] ; then - # Print file head - head -n $lines "$1" | cut -c 1-"$cols" - else - # Binary file + elif [ "$encoding" = "binary" ] ; then + # Binary file: just print filetype info echo "-------- Binary file --------" file -b "$1" + else + # Text file: print file head + head -n $lines "$1" | cut -c 1-"$cols" fi } -- cgit v1.2.3-70-g09d2