Skip to content

Commit

Permalink
[scripts] ,preview: show zlib compressed files
Browse files Browse the repository at this point in the history
  • Loading branch information
meain committed Sep 5, 2023
1 parent f4b7e93 commit 852744b
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions scripts/.local/bin/utils/,preview
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh

[ "$1" = "with-clear" ] && shift; ,icat-clear # use to be && instead of ;
[ "$1" = "with-clear" ] && shift
,icat-clear # use to be && instead of ;
imagepreview() {
if [ -n "$KITTY_WINDOW_ID" ]; then
timeout 4 kitty +kitten icat --place 60x"$2"@65x2 --transfer-mode file --silent "$1"
Expand All @@ -23,10 +24,10 @@ audiopreview() {

pdfpreview() {
if [ -n "$KITTY_WINDOW_ID" ]; then
pdftoppm -png -f 1 -l 1 -jpeg -tiffcompression jpeg "$1" > "/tmp/pdfpreview.jpg"
pdftoppm -png -f 1 -l 1 -jpeg -tiffcompression jpeg "$1" >"/tmp/pdfpreview.jpg"
imagepreview "/tmp/pdfpreview.jpg" "$2"
else
if ! pdftotext "$1" - ;then
if ! pdftotext "$1" -; then
pdftohtml "$1" -i -f 1 -l 3 -stdout >/tmp/pdfpage.html
w3m /tmp/pdfpage.html -dump
rm /tmp/pdfpage.html
Expand All @@ -37,13 +38,12 @@ pdfpreview() {
everythingelse() {
if [ -d "$1" ]; then
tree -L 1 -a "$1"
elif file --mime "$1" | grep 'charset=binary'; then
MIMETYPE="$(file --mime ade.sketch | cut -d' ' -f2)"
if echo "$MIMETYPE" | grep 'application/zip'; then
unzip -l "$1"
else
file -b "$1"
fi
elif file --mime "$1" | grep 'charset=binary'; then # no -q in grep to print the line
MIMETYPE="$(file --mime "$1" | cut -d' ' -f2 | cut -d';' -f1)"
case "$MIMETYPE" in
application/zip) echo "unzip" ; unzip -l "$1" ;;
application/zlib) zlib-flate -uncompress <"$1" ;; # FIXME prints "binary" if it has non char data
esac
else
jq <"$1" 2>/dev/null || cat "$1" || file "$1"
fi
Expand Down

0 comments on commit 852744b

Please sign in to comment.