aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/preview-tui
diff options
context:
space:
mode:
authorGravatar lvgx <l@vgx.fr>2020-05-22 04:48:00 +0200
committerGravatar GitHub <noreply@github.com>2020-05-22 08:18:00 +0530
commitadf381acee7a341c07ecd8514f1fc526bbb1abfd (patch)
tree3bdc995c3861793ea077fe4552d8d801704ef998 /plugins/preview-tui
parenta4909beb441aee350ff6508292f282bde5219516 (diff)
downloadnnn-adf381acee7a341c07ecd8514f1fc526bbb1abfd.tar.gz
Change binary file detection in preview-tui/kitty (#587)
Diffstat (limited to 'plugins/preview-tui')
-rwxr-xr-xplugins/preview-tui12
1 files changed, 6 insertions, 6 deletions
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
}