diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/preview | 38 |
1 files changed, 38 insertions, 0 deletions
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 |
