diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2020-05-03 14:55:33 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2020-05-03 14:55:33 +0530 |
commit | eee5057da5d5063f5a5c3e0059e98ad8f6ba179e (patch) | |
tree | 0351585ca189e49dbe7938d9636b63cb75479a5d /plugins | |
parent | e8e87f6ba2b72a8b7c2eb9a63d8a37a71f148882 (diff) | |
download | nnn-eee5057da5d5063f5a5c3e0059e98ad8f6ba179e.tar.gz |
Plugin mimelist: support reading file list from (cmd as) plugin
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/.nnn-plugin-helper | 2 | ||||
-rw-r--r-- | plugins/README.md | 13 | ||||
-rwxr-xr-x | plugins/autojump | 2 | ||||
-rwxr-xr-x | plugins/fzz | 2 | ||||
-rwxr-xr-x | plugins/mimelist | 21 |
5 files changed, 34 insertions, 6 deletions
diff --git a/plugins/.nnn-plugin-helper b/plugins/.nnn-plugin-helper index 06b3bcb..0f74fc7 100644 --- a/plugins/.nnn-plugin-helper +++ b/plugins/.nnn-plugin-helper @@ -29,7 +29,7 @@ nnn_cd () { read -r context fi - printf "%s" "${context:-0}$dir" > "$NNN_PIPE" + printf "%s" "${context:-0}c$dir" > "$NNN_PIPE" } cmd_exists () { diff --git a/plugins/README.md b/plugins/README.md index 9cafd3e..b16ef9e 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -47,6 +47,7 @@ Plugins are installed to `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins`. | kdeconnect | Send selected files to an Android device | sh | kdeconnect-cli | | launch | GUI application launcher | sh | fzf/fzy | | mediainf | Show media information | sh | mediainfo | +| mimelist | List files by mime in subtree | sh | fd/find | | moclyrics | Show lyrics of the track playing in moc | sh | [ddgr](https://github.com/jarun/ddgr), [moc](http://moc.daper.net/) | | mocplay | Append (and/or play) selection/dir/file in moc | sh | [moc](http://moc.daper.net/) | | mp3conv | Extract audio from multimedia as mp3 | sh | ffmpeg | @@ -163,8 +164,14 @@ Drop the plugin in `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins` and make it e #### Controlling `nnn`'s active directory `nnn` provides a mechanism for plugins to control its active directory. The way to do so is by writing to the pipe pointed by the environment variable `NNN_PIPE`. -The plugin should write a single string in the format `<number><path>` without a newline at the end. For example, `1/etc`. -The number indicates the context to change the active directory of (0 is used to indicate the current context). +The plugin should write a single string in the format `<context number><char><path>` without a newline at the end. For example, `1c/etc`. +The context number indicates the context to change the active directory of (0 is used to indicate the current context). +The `<char>` indicates the operation type. + +: Char : Operation : +|:---:| --- | +| c | cd | +| l | list files in list mode | For convenience, we provided a helper script named `.nnn-plugin-helper` and a function named `nnn_cd` to ease this process. `nnn_cd` receives the path to change to as the first argument, and the context as an optional second argument. If a context is not provided, it is asked for explicitly. To skip this and choose the current context, set the `CUR_CTX` variable in `.nnn-plugin-helper` to `1`. @@ -201,7 +208,7 @@ There are many plugins provided by `nnn` which can be used as examples. Here are printf "cd to: " read -r dir - printf "%s" "0$dir" > "$NNN_PIPE" + printf "%s" "0c$dir" > "$NNN_PIPE" ``` ## Contributing plugins diff --git a/plugins/autojump b/plugins/autojump index ef39dd9..db221f3 100755 --- a/plugins/autojump +++ b/plugins/autojump @@ -13,7 +13,7 @@ if which autojump >/dev/null 2>&1; then printf "jump to: " read -r dir odir="$(autojump "$dir")" - printf "%s" "0$odir" > "$NNN_PIPE" + printf "%s" "0c$odir" > "$NNN_PIPE" else printf "autojump missing" read -r _ diff --git a/plugins/fzz b/plugins/fzz index fa432c1..5b40269 100755 --- a/plugins/fzz +++ b/plugins/fzz @@ -25,4 +25,4 @@ else exit 1 fi -printf "%s" "0$sel" > "$NNN_PIPE" +printf "%s" "0c$sel" > "$NNN_PIPE" diff --git a/plugins/mimelist b/plugins/mimelist new file mode 100755 index 0000000..0ec7c0f --- /dev/null +++ b/plugins/mimelist @@ -0,0 +1,21 @@ +#!/usr/bin/env sh + +# Description: Run fd/find in subtree and list files by mime type in current context +# Requires: fd/find +# +# Shell: POSIX compliant +# Author: Arun Prakash jana + +. "$(dirname "$0")"/.nnn-plugin-helper + +if [ "$(cmd_exists fd)" -eq "0" ]; then + fd=fd +else + fd=find +fi + +printf "mime: " +read -r mime + +printf "%s" "0l" > "$NNN_PIPE" +$fd | file -if- | grep "$mime" | awk -F: '{printf "%s\0", $1}' > "$NNN_PIPE" |