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
|
2024-02-25 14:11:12 +01:00
|
|
|
*.mkv) mpv "$f"; ;;
|
|
|
|
*.mp4) mpv "$f"; ;;
|
|
|
|
*.webm) mpv "$f"; ;;
|
2023-11-01 10:14:00 +01:00
|
|
|
*) 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
|
2024-02-25 14:11:12 +01:00
|
|
|
*.mkv) mpv "$f"; ;;
|
|
|
|
*.mp4) mpv "$f"; ;;
|
|
|
|
*.webm) mpv "$f"; ;;
|
2023-11-01 10:14:00 +01:00
|
|
|
*) 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"; ;;
|
2024-02-25 14:11:12 +01:00
|
|
|
m2ts) mpv "$f"; ;;
|
|
|
|
flv) mpv "$f"; ;;
|
2024-01-08 23:06:28 +01:00
|
|
|
mp3) aplay "$f"; ;;
|
2024-01-05 12:30:05 +01:00
|
|
|
aiff) mpva "$f"; ;;
|
2023-11-01 10:14:00 +01:00
|
|
|
sid) sidplay "$f"; ;;
|
|
|
|
out) kdump -RTf "$f" | less; ;;
|
2023-11-19 08:40:50 +01:00
|
|
|
torrent) aria2c "$f"; ;;
|
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
|
2024-01-05 12:30:05 +01:00
|
|
|
application/ogg) aplay "$f"; ;;
|
2024-05-16 22:06:24 +02:00
|
|
|
application/pdf) zathura "$f"; ;;
|
|
|
|
application/postscript) zathura "$f"; ;;
|
2023-11-01 10:14:00 +01:00
|
|
|
application/vnd.oasis.opendocument.*) libreoffice "$f"; ;;
|
2024-01-05 12:30:05 +01:00
|
|
|
audio/mpeg) aplay "$f"; ;;
|
2023-11-01 10:14:00 +01:00
|
|
|
audio/midi) timidity "$f"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
# with wildcards
|
2024-01-05 12:30:05 +01:00
|
|
|
audio/*) aplay "$f"; ;;
|
2024-02-25 14:11:12 +01:00
|
|
|
video/*) mpv "$f"; ;;
|
|
|
|
image/webp) mpv "$f"; ;;
|
2023-11-09 07:23:05 +01:00
|
|
|
image/*) nsxiv -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
|
|
|
|
|