This repository has been archived on 2023-10-17. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.config/nnn/plugins/di-nuke

80 lines
1.6 KiB
Bash
Executable File

#! /bin/sh
FALLBACK_OPENER=xdg-open
entry="$1"
#mime="$(file -ibL "$entry" )"
FNAME=$(basename "$entry")
ext="${FNAME##*.}"
if [ -n "$ext" ]; then
ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
fi
case "${ext}" in
## Archive
a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zst|zip|rar|7z)
extract "$entry"
exit 0;;
## PDF
pdf)
zathura "$entry"
exit 1;;
## Audio
aac|flac|m4a|mid|midi|mpa|mp2|mp3|ogg|wav|wma)
mpv --no-video --quiet "$entry"
exit 1;;
## Video
avi|mkv|mp4|gif)
devour mpv "$entry"
exit 1;;
## Image
png|jpg|jpeg|PNG|JPG|JPEG|svg)
"$IMAGEVIEWER" "$entry"
exit 1;;
## Log files
log)
"$EDITOR" "$entry"
exit 0;;
## BitTorrent
torrenti|magnet)
aria2c -i "$entry"
exit 0;;
## OpenDocument
odt|ods|odp|sxw)
"$BROWSER" "$entry"
exit 0;;
## Markdown
md)
"$EDITOR" "$entry"
exit 0;;
## HTML
htm|html|xhtml)
## Preview as text conversion
"$BROWSER" "$entry"
exit 0;;
## JSON
json)
jq --color-output . "$entry"
exit 0 ;;
esac
case "$mime" in
*text*)
"$EDITOR" "$entry"
exit 0 ;;
esac
$FALLBACK_OPENER "$entry"