dotfiles/.bin/nnn.sh

105 lines
2.2 KiB
Bash
Executable File

#!/bin/ksh
f=$1
if [ -z "$f" ];
then
f="$(find $PWD $HOME $HOME/Downloads -maxdepth 1 -type f \
| sort -u \
| fzf -e -x -i)"
fi
###################################################
# URLS
###################################################
if print "$f" | egrep -qi '^shell:|^ushell:|^cvs:';
then
_server=${f%%:*}
_dir=${f#*:}
ssh -tt $_server "vim $_dir"
exit 0
fi
if print "$f" | egrep -qi '^http[s]{0,1}://';
then
case "$f" in
*.mkv) mpv "$f"; ;;
*.mp4) mpv "$f"; ;;
*.webm) mpv "$f"; ;;
*) sacc "$f"; ;;
esac
${BROWSER:=vimb} "$f"
exit 0
fi
if print "$f" | egrep -qi '^gopher://';
then
case "$f" in
*.mkv) mpv "$f"; ;;
*.mp4) mpv "$f"; ;;
*.webm) mpv "$f"; ;;
*) sacc "$f"; ;;
esac
exit 0
fi
###################################################
# REAL FILES
###################################################
if [ ! -f "$f" ];
then
print "Parameter is not a file."
exit 1
fi
###################################################
# EXTENSIONS
###################################################
EXT="$(print "${f##*.}" | tr '[:upper:]' '[:lower:]')"
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"; ;;
*) unset EXT; ;;
esac
if [ ! -z "$EXT" ];
then
exit 0;
fi
###################################################
# MIME TYPES
###################################################
case "$(file -ib "$f")" in
# full qualified
application/ogg) aplay "$f"; ;;
application/pdf) mupdf "$f"; ;;
application/postscript) mupdf "$f"; ;;
application/vnd.oasis.opendocument.*) libreoffice "$f"; ;;
audio/mpeg) aplay "$f"; ;;
audio/midi) timidity "$f"; ;;
# with wildcards
audio/*) aplay "$f"; ;;
video/*) mpv "$f"; ;;
image/webp) mpv "$f"; ;;
image/*) nsxiv -N floating -g 1280x720+300+180 -ab "$f"; ;;
# can't handle
application/octet-stream) print "Sorry, can't handle: $f"; ;;
# vim can handle a lot!
*) vim "$f"; ;;
esac