75 lines
1.6 KiB
Bash
75 lines
1.6 KiB
Bash
|
#!/bin/ksh
|
||
|
|
||
|
if [ -z "$1" ];
|
||
|
then
|
||
|
print "Parameter missing."
|
||
|
exit 2
|
||
|
fi
|
||
|
|
||
|
###################################################
|
||
|
# URLS
|
||
|
###################################################
|
||
|
|
||
|
if print "$1" | egrep -qi '^http[s]{0,1}://';
|
||
|
then
|
||
|
case "$1" in
|
||
|
*.mkv) mpv "$1"; ;;
|
||
|
*.mp4) mpv "$1"; ;;
|
||
|
*.webm) mpv "$1"; ;;
|
||
|
*) sacc "$1"; ;;
|
||
|
esac
|
||
|
${BROWSER:=firefox} "$1"
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
###################################################
|
||
|
# REAL FILES
|
||
|
###################################################
|
||
|
|
||
|
if [ ! -f "$1" ];
|
||
|
then
|
||
|
print "Parameter is not a file."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
###################################################
|
||
|
# BY EXTENSION
|
||
|
###################################################
|
||
|
|
||
|
EXT="$(print "${1##*.}" | tr '[:upper:]' '[:lower:]')"
|
||
|
|
||
|
case "$EXT" in
|
||
|
docx) libreoffice "$1"; ;;
|
||
|
xlsx) libreoffice "$1"; ;;
|
||
|
txt) vim "$1"; ;;
|
||
|
out) kdump -RTf "$1" | less; ;;
|
||
|
*) unset EXT; ;;
|
||
|
esac
|
||
|
|
||
|
if [ ! -z "$EXT" ];
|
||
|
then
|
||
|
exit 0;
|
||
|
fi
|
||
|
|
||
|
###################################################
|
||
|
# BY MIME TYPE
|
||
|
###################################################
|
||
|
|
||
|
case "$(file -ib "$1")" in
|
||
|
# full qualified
|
||
|
application/ogg) ogg123 "$1"; ;;
|
||
|
application/pdf) zathura "$1"; ;;
|
||
|
application/postscript) zathura "$1"; ;;
|
||
|
application/vnd.oasis.opendocument.*) libreoffice "$1"; ;;
|
||
|
audio/mpeg) mpg123 "$1"; ;;
|
||
|
audio/midi) timidity "$1"; ;;
|
||
|
# wildcards
|
||
|
audio/*) mpv "$1"; ;;
|
||
|
video/*) mpv "$1"; ;;
|
||
|
image/*) sxiv "$1"; ;;
|
||
|
# can't handle
|
||
|
application/octet-stream) print "Sorry, can't handle: $1"; ;;
|
||
|
# vim can handle a lot!
|
||
|
*) vim "$1"; ;;
|
||
|
esac
|