2020-05-03 12:25:33 +03:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
2020-11-22 17:39:14 +03:00
|
|
|
# Description: Find and list files by mime type in smart context
|
2020-05-03 12:25:33 +03:00
|
|
|
#
|
2024-02-09 18:16:15 +03:00
|
|
|
# Dependencies:
|
|
|
|
# - file
|
|
|
|
# - mimetype (optional, PERL File MimeInfo)
|
|
|
|
#
|
2020-05-03 12:25:33 +03:00
|
|
|
# Shell: POSIX compliant
|
2024-02-09 18:16:15 +03:00
|
|
|
# Author: Arun Prakash Jana, Michel DHOOGE
|
2020-05-03 12:25:33 +03:00
|
|
|
|
2022-07-16 20:47:32 +03:00
|
|
|
# shellcheck disable=SC1090,SC1091
|
2020-05-03 12:25:33 +03:00
|
|
|
. "$(dirname "$0")"/.nnn-plugin-helper
|
|
|
|
|
2020-11-12 05:47:14 +03:00
|
|
|
printf "mime (e.g., video/audio/image): "
|
2020-05-03 12:25:33 +03:00
|
|
|
read -r mime
|
|
|
|
|
2020-05-03 13:46:14 +03:00
|
|
|
printf "%s" "+l" > "$NNN_PIPE"
|
2024-02-09 18:16:15 +03:00
|
|
|
if type mimetype >/dev/null 2>&1; then
|
|
|
|
find . | mimetype -f - | grep "$mime" | awk -F: '{printf "%s%c", $1, 0}' > "$NNN_PIPE"
|
|
|
|
else
|
|
|
|
find . | file -if- | grep "$mime" | awk -F: '{printf "%s%c", $1, 0}' > "$NNN_PIPE"
|
|
|
|
fi
|