dotfiles/.bin/nnn.sh

101 lines
2.1 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
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
###################################################
if print "$f" | egrep -qi '^shell:|^ushell:|^cvs:';
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"; ;;
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
###################################################
case "$(file -ib "$f")" in
2022-12-06 08:01:44 +01:00
# full qualified
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
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
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