fix: use a more generic way to print NUL with awk

Only gawk undestands the \0 syntax
feat(mimelist): use `mimetype` for better type detection
docs(mimelist): add author & dependencies
This commit is contained in:
Michel DHOOGE 2024-02-09 16:16:15 +01:00 committed by Arun Prakash Jana
parent eb3888cb09
commit 5b05c8b9b1
No known key found for this signature in database
GPG Key ID: 4A865183AF6C5631
3 changed files with 12 additions and 4 deletions

2
nnn.1
View File

@ -353,7 +353,7 @@ Handy bash/zsh shell function to list files by mime-type in current directory:
list ()
{
find . -maxdepth 1 | file -if- | grep "$1" | awk -F: '{printf "%s\0", $1}' | nnn
find . -maxdepth 1 | file -if- | grep "$1" | awk -F: '{printf "%s%c", $1, 0}' | nnn
}
.Ed
.Pp

View File

@ -41,7 +41,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
| [ipinfo](ipinfo) | Fetch external IP address and whois information | sh | curl, whois |
| [kdeconnect](kdeconnect) | Send selected files to an Android device [✓] | sh | kdeconnect-cli |
| [launch](launch) | GUI application launcher | sh | fzf |
| [mimelist](mimelist) | List files by mime in subtree | sh | - |
| [mimelist](mimelist) | List files by mime in subtree | sh | file/mimetype |
| [moclyrics](moclyrics) | Show lyrics of the track playing in moc | sh | [ddgr](https://github.com/jarun/ddgr), [moc](http://moc.daper.net/) |
| [mocq](mocq) | Queue/play selection/dir/file in moc [✓] | sh | [moc](http://moc.daper.net/) |
| [mp3conv](mp3conv) | Extract audio from multimedia as mp3 | sh | ffmpeg |

View File

@ -2,8 +2,12 @@
# 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
# Author: Arun Prakash Jana, Michel DHOOGE
# shellcheck disable=SC1090,SC1091
. "$(dirname "$0")"/.nnn-plugin-helper
@ -12,4 +16,8 @@ printf "mime (e.g., video/audio/image): "
read -r mime
printf "%s" "+l" > "$NNN_PIPE"
find . | file -if- | grep "$mime" | awk -F: '{printf "%s\0", $1}' > "$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