Skip to content

Commit

Permalink
docs: 0.3 DDS
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Aug 5, 2024
1 parent b3bf6dc commit 5011a8e
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions docs/dds.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,35 @@ The DDS has three usage:

### Command-line tool {#cli}

You can send a message to the remote instance(s) using `ya pub`, with the two required `receiver` and `kind` arguments consistent with [`ps.pub_to()`](/docs/plugins/utils#ps.pub_to):
If you're in a Yazi subshell where the `$YAZI_ID` environment variable is set, you can send a message to the current instance using `ya pub`.

It requires a `<kind>` argument, which is consistent with [`ps.pub()`](/docs/plugins/utils#ps.pub):

```sh
ya pub <receiver> <kind> --str "string body"
ya pub <receiver> <kind> --json '{"key": "json body"}'
ya pub <kind> --str "string body"
ya pub <kind> --list "a" "b" "c"
ya pub <kind> --json '{"key":"json body"}'

# If you're in a Yazi subshell,
# you can obtain the ID of the current instance through `$YAZI_ID`.
ya pub "$YAZI_ID" dds-cd --str "/root"
# For example, request the current instance to extract `a.zip` and `b.7z`
ya pub extract --list "/root/a.zip" "/root/b.7z"
```

You can also send a static message to all remote instances using `ya pub-static`, with its `severity` and `kind` arguments consistent with [`ps.pub_static()`](/docs/plugins/utils#ps.pub_static):
You can also send a message to a specified remote instance(s) using `ya pub-to`, with the required `<severity>` and `<kind>` arguments, consistent with [`ps.pub_to()`](/docs/plugins/utils#ps.pub_to):

```sh
ya pub-static <severity> <kind> --str "string body"
ya pub-static <severity> <kind> --json '{"key": "json body"}'
ya pub-to <severity> <kind> --str "string body"
ya pub-to <severity> <kind> --list "a" "b" "c"
ya pub-to <severity> <kind> --json '{"key":"json body"}'

# If you're in a Yazi subshell,
# you can obtain the ID of the current instance through `$YAZI_ID`.
ya pub-to "$YAZI_ID" dds-cd --str "/root"
```

For greater convenience in integrating within the command-line environment, they support two body formats:

- String: a straightforward format, suitable for most scenarios, without the need for additional tools for encoding
- List: An array of strings, it is useful for carrying a file list to the message, through `$@` in your shell
- JSON: for advanced needs, support for types and more complex data can be represented through the JSON format

Note that `ya` is a standalone CLI program introduced since Yazi 0.2.5, it might conflict with the shell wrapper you setup before, see [Introduce a standalone CLI program](https://github.com/sxyazi/yazi/issues/914) for details.
Expand Down Expand Up @@ -377,7 +385,7 @@ This is useful for synchronizing the CWD of the current Yazi instance when exiti
# Change Yazi's CWD to PWD on subshell exit
if [[ -n "$YAZI_ID" ]]; then
function _yazi_cd() {
ya pub "$YAZI_ID" dds-cd --str "$PWD"
ya pub dds-cd --str "$PWD"
}
add-zsh-hook zshexit _yazi_cd
fi
Expand Down Expand Up @@ -415,3 +423,18 @@ require("session"):setup {
```

Source code: https://github.com/sxyazi/yazi/blob/main/yazi-plugin/preset/plugins/session.lua

### `extract.lua` {#extract.lua}

The plugin provides an `extract` event kind for archive extraction, which accepts an array of file URL. You can bind it as [the opener](/docs/configuration/yazi#opener) for archives:

```toml
# ~/.config/yazi/yazi.toml
[opener]
extract = [
{ run = 'ya pub extract --list "$@"', desc = "Extract here", for = "unix" },
{ run = 'ya pub extract --list %*', desc = "Extract here", for = "windows" },
]
```

Source code: https://github.com/sxyazi/yazi/blob/main/yazi-plugin/preset/plugins/extract.lua

0 comments on commit 5011a8e

Please sign in to comment.