91 lines
2.0 KiB
Bash
Executable File
91 lines
2.0 KiB
Bash
Executable File
#!/bin/ksh
|
|
|
|
f="$1"
|
|
|
|
if [ -z "$f" ];
|
|
then
|
|
echo "no argument given"
|
|
exit 2
|
|
fi
|
|
|
|
###################################################
|
|
# SSH
|
|
###################################################
|
|
|
|
# SSH
|
|
if print "$f" | egrep -qi '^shell:|^ushell:|^cvs:|^home:';
|
|
then
|
|
_server=${f%%:*}
|
|
_dir=${f#*:}
|
|
ssh -tt $_server "vim $_dir"
|
|
exit 0
|
|
fi
|
|
|
|
###################################################
|
|
# TRY TO FIND MIME TYPE
|
|
###################################################
|
|
if print "$f" | egrep -qi '^http[s]{0,1}://';
|
|
then
|
|
MIME="$(webmime "$f")"
|
|
TYPE="http"
|
|
fi
|
|
|
|
if print "$f" | egrep -qi '^gopher[s]{0,1}://';
|
|
then
|
|
MIME=""
|
|
TYPE="gopher"
|
|
fi
|
|
|
|
if [ -f "$f" ]
|
|
then
|
|
MIME="$(file -ib "$f")"
|
|
TYPE="file"
|
|
fi
|
|
|
|
###################################################
|
|
# 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
|
|
|
|
# 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"; ;;
|
|
esac
|
|
echo "TYPE=$TYPE | MIME=$MIME | EXT=.$EXT | EXEC=$EXEC"
|
|
|
|
[ ! -z "$EXEC" ] && exec $EXEC "$f"
|
|
exit 0
|