dotfiles.git

commit 6dbf96286972809c99c751ed191f3b4d1b99af9d

Author: Adam Evyčędo <git@apiote.xyz>

preview, view and edit fixes

 .config/lf/previewer.sh | 2 +-
 .config/sh/functions | 42 +++++++++++++++++++++++++++++++++++++++---


diff --git a/.config/lf/previewer.sh b/.config/lf/previewer.sh
index 65d2bd582433740f48143405c0b1d12c79e6adc0..ed23507161ed2a17260847d2df982eb55122a5ea 100755
--- a/.config/lf/previewer.sh
+++ b/.config/lf/previewer.sh
@@ -3,4 +3,4 @@
 . ~/.config/sh/variables
 . ~/.config/sh/functions
 
-view "$1"
+preview "$1"




diff --git a/.config/sh/functions b/.config/sh/functions
index ab69cd60615b80b54110da7716cd049f38e6d16a..789fe8e4cee6b431d4ca8258ae0b3bd2ed042a61 100644
--- a/.config/sh/functions
+++ b/.config/sh/functions
@@ -736,28 +736,64 @@ 		luakit "$1"
 		exit
 	fi
 
-	# TODO add json, links; 'me.asc: application/pgp-keys; charset=us-ascii'
 	mime=$(file -i "$1" | cut -d ':' -f2 | cut -d ';' -f1 | tr -d ' ')
+	charset=$(file -i "$1" | cut -d ':' -f2 | cut -d ';' -f2 | tr -d ' ')
 	case $mime in
 		text/*) bat -f "$1" ;;
 		image/*) setsid swayimg "$1" >/dev/null 2>&1 & ;;
-		video/*) setsid mpv "$1" >/dev/null 2>&1 & ;;
-		audio/*) setsid mpa "$1" >/dev/null 2>&1 & ;;
+		video/*) mpv "$1" >/dev/null 2>&1 & ;;
+		audio/*) mpa "$1" >/dev/null 2>&1 & ;;
+		application/json) bat -f "$1" ;;
+		application/javascript) bat -f "$1" ;;
 		application/pdf) setsid zathura "$1" >/dev/null 2>&1 & ;;
 		application/epub+zip) setsid zathura "$1" >/dev/null 2>&1 & ;;
 		application/zip) unzip -l "$1" ;;
+		application/pgp-keys)
+			if [ "$charset" = 'us-ascii' ]
+			then
+				bat -f "$1"
+			else
+				hexyl "$1"
+			fi
+		;;
 		application/x-bzip2|application/gzip|application/x-tar) tar tvf "$1" ;;
 		*) hexyl "$1" ;;
 	esac
 }
 
+preview() {
+	mime=$(file -i "$1" | cut -d ':' -f2 | cut -d ';' -f1 | tr -d ' ')
+	charset=$(file -i "$1" | cut -d ':' -f2 | cut -d ';' -f2 | tr -d ' ')
+	# TODO images, maybe stills from videos, pdfs, zstd in tar
+	case $mime in
+		text/*) view "$1" ;;
+		image/*|video/*|audio/*) ffprobe "$1" 2>&1;;
+		application/json) view "$1" ;;
+		application/javascript) view "$1" ;;
+		application/pdf) bat "$1" ;;
+		application/epub+zip) unzip -l "$1" ;;
+		application/zip) view "$1" ;;
+		application/pgp-keys) view "$1" ;;
+		application/x-bzip2|application/gzip|application/x-tar) view "$1" ;;
+		application/zstd)
+			zstd -dfk "$1" -o /tmp/hgsdhsbfksabfasdfbjhbcsdygreyb.tar >/dev/null 2>&1
+			tar tvf /tmp/hgsdhsbfksabfasdfbjhbcsdygreyb.tar
+			rm /tmp/hgsdhsbfksabfasdfbjhbcsdygreyb.tar
+		;;
+		*) view "$1" ;;
+	esac
+}
+
 edit() {
 	mime=$(file -i "$1" | cut -d ':' -f2 | cut -d ';' -f1 | tr -d ' ')
+	charset=$(file -i "$1" | cut -d ':' -f2 | cut -d ';' -f2 | tr -d ' ')
 	case $mime in
 		text/*) hx "$1" ;;
 		image/*) setsid gimp "$1" >/dev/null 2>&1 & ;;
 		video/*) setsid kdenlive  "$1" >/dev/null 2>&1 & ;;
 		audio/*) setsid audacity "$1" >/dev/null 2>&1 & ;;
+		application/json) hx "$1" ;;
+		application/javascript) hx "$1" ;;
 		application/pdf) setsid gimp "$1" >/dev/null 2>&1 & ;;
 		application/epub+zip) setsid sigil "$1" >/dev/null 2>&1 & ;;
 		application/zip|application/x-bzip2|application/gzip|application/x-tar) setsid file-roller "$1" >/dev/null 2>&1 & ;;