79 lines
1.6 KiB
Bash
Executable file
79 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)
|
|
"$BROWSER" "$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)
|
|
display -resize '800x800!' "$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"
|