dotfiles/.bin/nnn.sh

104 lines
2.2 KiB
Bash
Raw Normal View History

2022-12-06 08:01:44 +01:00
#!/bin/ksh
f=$1
if [ -z "$f" ];
2022-12-06 08:01:44 +01:00
then
echo "no argument given"
exit 2
2022-12-06 08:01:44 +01:00
fi
###################################################
# URLS
###################################################
if print "$f" | egrep -qi '^shell:|^ushell:|^cvs:|^home:';
2022-12-06 08:01:44 +01:00
then
_server=${f%%:*}
_dir=${f#*:}
2022-12-06 08:01:44 +01:00
ssh -tt $_server "vim $_dir"
exit 0
fi
if print "$f" | egrep -qi '^http[s]{0,1}://';
2022-12-06 08:01:44 +01:00
then
case "$f" in
*.mkv) mpv "$f"; ;;
*.mp4) mpv "$f"; ;;
*.webm) mpv "$f"; ;;
*) sacc "$f"; ;;
2022-12-06 08:01:44 +01:00
esac
${BROWSER:=vimb} "$f"
2022-12-06 08:01:44 +01:00
exit 0
fi
if print "$f" | egrep -qi '^gopher://';
2022-12-06 08:01:44 +01:00
then
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
###################################################
if [ ! -f "$f" ];
2022-12-06 08:01:44 +01:00
then
print "Parameter is not a file."
exit 1
fi
###################################################
# EXTENSIONS
###################################################
EXT="$(print "${f##*.}" | tr '[:upper:]' '[:lower:]')"
2022-12-06 08:01:44 +01:00
case "$EXT" in
docx) libreoffice "$f"; ;;
xlsx) libreoffice "$f"; ;;
txt) vim "$f"; ;;
m2ts) mpv "$f"; ;;
flv) mpv "$f"; ;;
mp3) aplay "$f"; ;;
aiff) mpva "$f"; ;;
sid) sidplay "$f"; ;;
out) kdump -RTf "$f" | less; ;;
torrent) aria2c "$f"; ;;
2022-12-06 08:01:44 +01:00
*) unset EXT; ;;
esac
if [ ! -z "$EXT" ];
then
exit 0;
fi
###################################################
# MIME TYPES
###################################################
case "$(file -ib "$f")" in
2022-12-06 08:01:44 +01:00
# full qualified
application/ogg) aplay "$f"; ;;
application/pdf) zathura "$f"; ;;
application/postscript) zathura "$f"; ;;
application/vnd.oasis.opendocument.*) libreoffice "$f"; ;;
audio/mpeg) aplay "$f"; ;;
audio/midi) timidity "$f"; ;;
2022-12-06 08:01:44 +01:00
# with wildcards
audio/*) aplay "$f"; ;;
video/*) mpv "$f"; ;;
image/webp) mpv "$f"; ;;
image/*) nsxiv -N floating -g 1280x720+300+180 -ab "$f"; ;;
2022-12-06 08:01:44 +01:00
# can't handle
application/octet-stream) print "Sorry, can't handle: $f"; ;;
2022-12-06 08:01:44 +01:00
# vim can handle a lot!
*) vim "$f"; ;;
2022-12-06 08:01:44 +01:00
esac