From e0d79e6c570d02f353039a0057f0e8036b6e6511 Mon Sep 17 00:00:00 2001 From: JP Appel Date: Sun, 1 Sep 2024 17:23:35 -0400 Subject: feat: zsh file browser + previewer --- scripts/preview | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 scripts/preview (limited to 'scripts') diff --git a/scripts/preview b/scripts/preview new file mode 100755 index 0000000..2528082 --- /dev/null +++ b/scripts/preview @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +path="$1" +lines="$2" + +# TODO: if lines is undefined set to 40 +# TODO: truncate long output to lines + +[ ! -e "$path" ] && { echo "$path not found" ; exit 1; } + +filetype=$(file -b "$path") + +if grep -q "text" <<< "$filetype"; then + filetype="text" +elif grep -q "archive" <<< "$filetpye"; then + filetype="archive" +elif grep -q "ISO" <<< "$filetype" ; then + filetype="iso" +fi + +case $filetype in + "directory") + fd . "$path" + ;; + "text") + bat -p -r ":$lines" --color=always "$path" + ;; + "archive") + echo "archive preview not currently supported" + file -b "$path" + ;; + "iso") + isoinfo -l -i "$path" | head -n "$lines" + ;; + *) + file -b "$path" + ;; +esac -- cgit v1.2.3