diff options
author | 2020-05-03 16:16:14 +0530 | |
---|---|---|
committer | 2020-05-03 16:25:59 +0530 | |
commit | ebb6f153b51332ce2b64b3e717ea956484749d4c (patch) | |
tree | fb798e3b34d5120292b9aa53f3cd2f9c3e4d19c7 /plugins | |
parent | 3f60a1931f1e51c8e90516dd7e716244da7f42e7 (diff) | |
download | nnn-ebb6f153b51332ce2b64b3e717ea956484749d4c.tar.gz |
Context code '+' to create context smartly
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/README.md | 24 | ||||
-rwxr-xr-x | plugins/mimelist | 4 |
2 files changed, 18 insertions, 10 deletions
diff --git a/plugins/README.md b/plugins/README.md index b16ef9e..3067236 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -161,17 +161,25 @@ Plugins can be written in any scripting language. However, POSIX-compliant shell Drop the plugin in `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins` and make it executable. Optionally add a hotkey in `$NNN_PLUG` for frequent usage. -#### Controlling `nnn`'s active directory -`nnn` provides a mechanism for plugins to control its active directory. +#### Send data to `nnn` +`nnn` provides a mechanism for plugins to send data to `nnn` to control its active directory or invoke the list mode. 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 `<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. +The plugin should write a single string in the format `<ctxcode><opcode><data>` without a newline at the end. For example, `1c/etc`. -: Char : Operation : +The `ctxcode` indicates the context to change the active directory of. + +| Context code | Meaning | +|:---:| --- | +| `1`-`4` | context number | +| `0` | current context | +| `+` | next inactive context or current (if all active) | + +The `opcode` indicates the operation type. + +| Opcode | Operation | |:---:| --- | -| c | cd | -| l | list files in list mode | +| `c` | change directory | +| `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`. diff --git a/plugins/mimelist b/plugins/mimelist index 0ec7c0f..5635afd 100755 --- a/plugins/mimelist +++ b/plugins/mimelist @@ -1,6 +1,6 @@ #!/usr/bin/env sh -# Description: Run fd/find in subtree and list files by mime type in current context +# Description: Run fd/find in subtree and list files by mime type in smart context # Requires: fd/find # # Shell: POSIX compliant @@ -17,5 +17,5 @@ fi printf "mime: " read -r mime -printf "%s" "0l" > "$NNN_PIPE" +printf "%s" "+l" > "$NNN_PIPE" $fd | file -if- | grep "$mime" | awk -F: '{printf "%s\0", $1}' > "$NNN_PIPE" |