2022-12-06 08:01:44 +01:00
|
|
|
#!/bin/ksh
|
|
|
|
|
2023-11-01 10:14:00 +01:00
|
|
|
f=$1
|
|
|
|
|
|
|
|
if [ -z "$f" ];
|
2022-12-06 08:01:44 +01:00
|
|
|
then
|
2023-11-01 10:14:00 +01:00
|
|
|
f="$(find $PWD $HOME $HOME/Downloads -maxdepth 1 -type f \
|
|
|
|
| sort -u \
|
|
|
|
| fzf -e -x -i)"
|
2022-12-06 08:01:44 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
###################################################
|
|
|
|
# URLS
|
|
|
|
###################################################
|
|
|
|
|
2023-11-01 10:14:00 +01:00
|
|
|
if print "$f" | egrep -qi '^shell:|^ushell:|^cvs:';
|
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
|
|
|
|
|
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
|
2023-11-01 10:14:00 +01:00
|
|
|
case "$f" in
|
|
|
|
*.mkv) mpv "$f"; ;;
|
|
|
|
*.mp4) mpv "$f"; ;;
|
|
|
|
*.webm) mpv "$f"; ;;
|
|
|
|
*) sacc "$f"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
esac
|
2023-11-01 10:14:00 +01:00
|
|
|
${BROWSER:=vimb} "$f"
|
2022-12-06 08:01:44 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-11-01 10:14:00 +01:00
|
|
|
if print "$f" | egrep -qi '^gopher://';
|
2022-12-06 08:01:44 +01:00
|
|
|
then
|
2023-11-01 10:14:00 +01:00
|
|
|
case "$f" in
|
|
|
|
*.mkv) mpv "$f"; ;;
|
|
|
|
*.mp4) mpv "$f"; ;;
|
|
|
|
*.webm) mpv "$f"; ;;
|
|
|
|
*) sacc "$f"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
esac
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
###################################################
|
|
|
|
# REAL FILES
|
|
|
|
###################################################
|
|
|
|
|
2023-11-01 10:14:00 +01:00
|
|
|
if [ ! -f "$f" ];
|
2022-12-06 08:01:44 +01:00
|
|
|
then
|
|
|
|
print "Parameter is not a file."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
###################################################
|
|
|
|
# EXTENSIONS
|
|
|
|
###################################################
|
|
|
|
|
2023-11-01 10:14:00 +01:00
|
|
|
EXT="$(print "${f##*.}" | tr '[:upper:]' '[:lower:]')"
|
2022-12-06 08:01:44 +01:00
|
|
|
|
|
|
|
case "$EXT" in
|
2023-11-01 10:14:00 +01:00
|
|
|
docx) libreoffice "$f"; ;;
|
|
|
|
xlsx) libreoffice "$f"; ;;
|
|
|
|
txt) vim "$f"; ;;
|
|
|
|
m2ts) mpv "$f"; ;;
|
|
|
|
sid) sidplay "$f"; ;;
|
|
|
|
out) kdump -RTf "$f" | less; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
*) unset EXT; ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ ! -z "$EXT" ];
|
|
|
|
then
|
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
|
|
|
|
###################################################
|
|
|
|
# MIME TYPES
|
|
|
|
###################################################
|
|
|
|
|
2023-11-01 10:14:00 +01:00
|
|
|
case "$(file -ib "$f")" in
|
2022-12-06 08:01:44 +01:00
|
|
|
# full qualified
|
2023-11-01 10:14:00 +01:00
|
|
|
application/ogg) ogg123 "$f"; ;;
|
|
|
|
application/pdf) mupdf-gl -XJA0 "$f"; ;;
|
|
|
|
application/postscript) mupdf-gl -XJA0 "$f"; ;;
|
|
|
|
application/vnd.oasis.opendocument.*) libreoffice "$f"; ;;
|
|
|
|
audio/mpeg) mpg123 "$f"; ;;
|
|
|
|
audio/midi) timidity "$f"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
# with wildcards
|
2023-11-01 10:14:00 +01:00
|
|
|
audio/*) mpv "$f"; ;;
|
|
|
|
video/*) mpv "$f"; ;;
|
|
|
|
image/webp) mpv "$f"; ;;
|
|
|
|
image/*) sxiv -N floating -g 1280x720+300+180 -ab "$f"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
# can't handle
|
2023-11-01 10:14:00 +01:00
|
|
|
application/octet-stream) print "Sorry, can't handle: $f"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
# vim can handle a lot!
|
2023-11-01 10:14:00 +01:00
|
|
|
*) vim "$f"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
esac
|
|
|
|
|