File: mimelist

package info (click to toggle)
nnn 5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,184 kB
  • sloc: ansic: 11,902; sh: 3,585; makefile: 512; cpp: 80; python: 31; csh: 2
file content (23 lines) | stat: -rwxr-xr-x 617 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env sh

# Description: Find and list files by mime type in smart context
#
# Dependencies:
#   - file
#   - mimetype (optional, PERL File MimeInfo)
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana, Michel DHOOGE

# shellcheck disable=SC1090,SC1091
. "$(dirname "$0")"/.nnn-plugin-helper

printf "mime (e.g., video/audio/image): "
read -r mime

printf "%s" "+l" > "$NNN_PIPE"
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