Update 2024-10-20 18:21 OpenBSD/amd64-t14

This commit is contained in:
c0dev0id 2024-10-20 18:21:51 +02:00
parent 634ce7bc79
commit de5b108398
2 changed files with 54 additions and 67 deletions

View File

@ -1,6 +1,6 @@
#!/bin/ksh #!/bin/ksh
f=$1 f="$1"
if [ -z "$f" ]; if [ -z "$f" ];
then then
@ -9,9 +9,10 @@ then
fi fi
################################################### ###################################################
# URLS # SSH
################################################### ###################################################
# SSH
if print "$f" | egrep -qi '^shell:|^ushell:|^cvs:|^home:'; if print "$f" | egrep -qi '^shell:|^ushell:|^cvs:|^home:';
then then
_server=${f%%:*} _server=${f%%:*}
@ -20,84 +21,70 @@ then
exit 0 exit 0
fi fi
###################################################
# TRY TO FIND MIME TYPE
###################################################
if print "$f" | egrep -qi '^http[s]{0,1}://'; if print "$f" | egrep -qi '^http[s]{0,1}://';
then then
case "$f" in MIME="$(webmime "$f")"
*.mkv) mpv "$f"; ;; TYPE="http"
*.mp4) mpv "$f"; ;;
*.webm) mpv "$f"; ;;
*) sacc "$f"; ;;
esac
${BROWSER:=vimb} "$f"
exit 0
fi fi
if print "$f" | egrep -qi '^gopher://'; if print "$f" | egrep -qi '^gopher[s]{0,1}://';
then then
case "$f" in MIME=""
*.mkv) mpv "$f"; ;; TYPE="gopher"
*.mp4) mpv "$f"; ;;
*.webm) mpv "$f"; ;;
*) sacc "$f"; ;;
esac
exit 0
fi fi
################################################### if [ -f "$f" ]
# REAL FILES
###################################################
if [ ! -f "$f" ];
then then
print "Parameter is not a file." MIME="$(file -ib "$f")"
exit 1 TYPE="file"
fi fi
################################################### ###################################################
# EXTENSIONS # TRANSLATE MIME TYPES TO EXTENSIONS
################################################### ###################################################
case "$MIME" in
# full qualified
application/ogg) EXT=ogg; ;;
application/pdf) EXT=pdf; ;;
application/postscript) EXT=ps; ;;
application/vnd.oasis.opendocument.*) EXT=docx; ;;
audio/mpeg) EXT=mpg; ;;
audio/midi) EXT=midi; ;;
image/webp) EXT=webp; ;;
application/x-gzip) EXT=gz; ;;
# with wildcards
audio/*) EXT=generic_audio; ;;
video/*) EXT=generic_video; ;;
image/*) EXT=generic_image; ;;
# vim can handle a lot!
text/*) EXT=generic_text; ;;
esac
EXT="$(print "${f##*.}" | tr '[:upper:]' '[:lower:]')" # no extension yet? Extract from file
[ -z "$EXT" ] && EXT="$(print "${f##*.}" | tr '[:upper:]' '[:lower:]')"
case "$EXT" in case "$EXT" in
docx) libreoffice "$f"; ;; aiff) EXEC="mpv"; ;;
xlsx) libreoffice "$f"; ;; mkv) EXEC="mpv"; ;;
txt) vim "$f"; ;; docx) EXEC="libreoffice"; ;;
m2ts) mpv "$f"; ;; flv) EXEC="mpv"; ;;
flv) mpv "$f"; ;; m2ts) EXEC="mpv"; ;;
mp3) aplay "$f"; ;; mp3) EXEC_TERM="aplay"; ;;
aiff) mpva "$f"; ;; mp4) EXEC="mpv"; ;;
sid) sidplay "$f"; ;; out) EXEC="kdump -RTf"; ;;
out) kdump -RTf "$f" | less; ;; sid) EXEC="sidplay"; ;;
torrent) aria2c "$f"; ;; torrent) EXEC="aria2c"; ;;
*) unset EXT; ;; txt) EXEC="vim"; ;;
esac webm) EXEC="mpv"; ;;
xlsx) EXEC="libreoffice"; ;;
if [ ! -z "$EXT" ]; generic_text) EXEC="vim"; ;;
then generic_video) EXEC="mpv"; ;;
exit 0; generic_audio) EXEC="mpv"; ;;
fi
###################################################
# MIME TYPES
###################################################
case "$(file -ib "$f")" in
# full qualified
application/ogg) aplay "$f"; ;;
application/pdf) zathura "$f"; ;;
application/postscript) zathura "$f"; ;;
application/vnd.oasis.opendocument.*) libreoffice "$f"; ;;
audio/mpeg) aplay "$f"; ;;
audio/midi) timidity "$f"; ;;
# with wildcards
audio/*) aplay "$f"; ;;
video/*) mpv "$f"; ;;
image/webp) mpv "$f"; ;;
image/*) nsxiv -N floating -g 1280x720+300+180 -ab "$f"; ;;
# can't handle
application/octet-stream) print "Sorry, can't handle: $f"; ;;
# vim can handle a lot!
*) vim "$f"; ;;
esac esac
echo "TYPE=$TYPE | MIME=$MIME | EXT=.$EXT | EXEC=$EXEC"
[ ! -z "$EXEC" ] && exec $EXEC "$f"
exit 0

View File

@ -23,4 +23,4 @@ then
exit 1 exit 1
fi fi
echo "$R" echo "$R" | col -b