commit 5b05c8b9b1e6fe5549680465e05aa89f45d265df
parent eb3888cb09e9152f3c135057639c2e8b44dd18e5
Author: Michel DHOOGE <426441+mdhooge@users.noreply.github.com>
Date: Fri, 9 Feb 2024 16:16:15 +0100
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
Diffstat:
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/nnn.1 b/nnn.1
@@ -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
diff --git a/plugins/README.md b/plugins/README.md
@@ -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 |
diff --git a/plugins/mimelist b/plugins/mimelist
@@ -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