2022-12-06 08:01:44 +01:00
|
|
|
#!/bin/ksh
|
|
|
|
|
2024-10-20 18:21:51 +02:00
|
|
|
f="$1"
|
2023-11-01 10:14:00 +01:00
|
|
|
|
|
|
|
if [ -z "$f" ];
|
2022-12-06 08:01:44 +01:00
|
|
|
then
|
2024-10-20 07:57:21 +02:00
|
|
|
echo "no argument given"
|
|
|
|
exit 2
|
2022-12-06 08:01:44 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
###################################################
|
2024-10-20 18:21:51 +02:00
|
|
|
# SSH
|
2022-12-06 08:01:44 +01:00
|
|
|
###################################################
|
|
|
|
|
2024-10-20 18:21:51 +02:00
|
|
|
# SSH
|
2024-10-20 07:57:21 +02:00
|
|
|
if print "$f" | egrep -qi '^shell:|^ushell:|^cvs:|^home:';
|
2022-12-06 08:01:44 +01:00
|
|
|
then
|
2023-11-01 10:14:00 +01:00
|
|
|
_server=${f%%:*}
|
|
|
|
_dir=${f#*:}
|
2022-12-06 08:01:44 +01:00
|
|
|
ssh -tt $_server "vim $_dir"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2024-10-20 18:21:51 +02:00
|
|
|
###################################################
|
|
|
|
# TRY TO FIND MIME TYPE
|
|
|
|
###################################################
|
2023-11-01 10:14:00 +01:00
|
|
|
if print "$f" | egrep -qi '^http[s]{0,1}://';
|
2022-12-06 08:01:44 +01:00
|
|
|
then
|
2024-10-20 18:21:51 +02:00
|
|
|
MIME="$(webmime "$f")"
|
|
|
|
TYPE="http"
|
2022-12-06 08:01:44 +01:00
|
|
|
fi
|
|
|
|
|
2024-10-20 18:21:51 +02:00
|
|
|
if print "$f" | egrep -qi '^gopher[s]{0,1}://';
|
2022-12-06 08:01:44 +01:00
|
|
|
then
|
2024-10-20 18:21:51 +02:00
|
|
|
MIME=""
|
|
|
|
TYPE="gopher"
|
2022-12-06 08:01:44 +01:00
|
|
|
fi
|
|
|
|
|
2024-10-20 18:21:51 +02:00
|
|
|
if [ -f "$f" ]
|
2022-12-06 08:01:44 +01:00
|
|
|
then
|
2024-10-20 18:21:51 +02:00
|
|
|
MIME="$(file -ib "$f")"
|
|
|
|
TYPE="file"
|
2022-12-06 08:01:44 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
###################################################
|
2024-10-20 18:21:51 +02:00
|
|
|
# TRANSLATE MIME TYPES TO EXTENSIONS
|
2022-12-06 08:01:44 +01:00
|
|
|
###################################################
|
2024-10-20 18:21:51 +02:00
|
|
|
case "$MIME" in
|
2022-12-06 08:01:44 +01:00
|
|
|
# full qualified
|
2024-10-20 18:21:51 +02:00
|
|
|
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; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
# with wildcards
|
2024-10-20 18:21:51 +02:00
|
|
|
audio/*) EXT=generic_audio; ;;
|
|
|
|
video/*) EXT=generic_video; ;;
|
|
|
|
image/*) EXT=generic_image; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
# vim can handle a lot!
|
2024-10-20 18:21:51 +02:00
|
|
|
text/*) EXT=generic_text; ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# no extension yet? Extract from file
|
|
|
|
[ -z "$EXT" ] && EXT="$(print "${f##*.}" | tr '[:upper:]' '[:lower:]')"
|
|
|
|
|
|
|
|
case "$EXT" in
|
|
|
|
aiff) EXEC="mpv"; ;;
|
|
|
|
mkv) EXEC="mpv"; ;;
|
|
|
|
docx) EXEC="libreoffice"; ;;
|
|
|
|
flv) EXEC="mpv"; ;;
|
|
|
|
m2ts) EXEC="mpv"; ;;
|
|
|
|
mp3) EXEC_TERM="aplay"; ;;
|
|
|
|
mp4) EXEC="mpv"; ;;
|
|
|
|
out) EXEC="kdump -RTf"; ;;
|
|
|
|
sid) EXEC="sidplay"; ;;
|
|
|
|
torrent) EXEC="aria2c"; ;;
|
|
|
|
txt) EXEC="vim"; ;;
|
|
|
|
webm) EXEC="mpv"; ;;
|
|
|
|
xlsx) EXEC="libreoffice"; ;;
|
|
|
|
generic_text) EXEC="vim"; ;;
|
|
|
|
generic_video) EXEC="mpv"; ;;
|
|
|
|
generic_audio) EXEC="mpv"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
esac
|
2024-10-20 18:21:51 +02:00
|
|
|
echo "TYPE=$TYPE | MIME=$MIME | EXT=.$EXT | EXEC=$EXEC"
|
2022-12-06 08:01:44 +01:00
|
|
|
|
2024-10-20 18:21:51 +02:00
|
|
|
[ ! -z "$EXEC" ] && exec $EXEC "$f"
|
|
|
|
exit 0
|