diff --git a/nnn.1 b/nnn.1 index 0dd3eaeb..d4a06044 100644 --- 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 index caff819e..377071dd 100644 --- 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 index ccfe05a9..3813c092 100755 --- 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