aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2024-09-01 17:23:35 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2024-09-01 17:23:35 -0400
commite0d79e6c570d02f353039a0057f0e8036b6e6511 (patch)
tree81c1ceae3d3e48a48f2166ce1a1a708d008b9b3d /scripts
parentc9658790bd19de81abc5f2f5565ec66f6099e5b6 (diff)
feat: zsh file browser + previewer
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/preview38
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