dotfiles/.bin/nnn.sh

105 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
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) tmpv "$f"; ;;
*.mp4) tmpv "$f"; ;;
*.webm) tmpv "$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) tmpv "$f"; ;;
*.mp4) tmpv "$f"; ;;
*.webm) tmpv "$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) tmpv "$f"; ;;
flv) tmpv "$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) mupdf "$f"; ;;
application/postscript) mupdf "$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/*) tmpv "$f"; ;;
image/webp) tmpv "$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