aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2023-06-26 21:23:01 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2023-06-26 21:23:01 +0200
commite730452fd8bd6824d35f25f2e87b8ec788b626fd (patch)
tree9207c548ae0f67c24778f18046ec12698902c54d /src/tools
parent666d80e2586b302239e49deb62b5418160b6dd9d (diff)
downloadnotes-e730452fd8bd6824d35f25f2e87b8ec788b626fd.tar.gz
notes-e730452fd8bd6824d35f25f2e87b8ec788b626fd.zip
zsh: add completion example for positional args
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/zsh.md25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/tools/zsh.md b/src/tools/zsh.md
index ab50644..a1302a4 100644
--- a/src/tools/zsh.md
+++ b/src/tools/zsh.md
@@ -284,8 +284,8 @@ blu -- desc for blu
_arguments SPEC [SPEC...]
```
where `SPEC` can have one of the following forms:
-- `OPT[DESC]:MSG:ACTION`
-- `N:MSG:ACTION`
+- `OPT[DESC]:MSG:ACTION` for option flags
+- `N:MSG:ACTION` for positional arguments
Available actions
```zsh
@@ -329,6 +329,27 @@ function _foo() {
}
```
+### Example with optional arguments
+For this example we assume that the command `foo` takes at least three optional
+arguments such as
+```zsh
+foo arg1 arg2 arg3 [argN..]
+```
+
+```zsh
+function _foo() {
+ _arguments \
+ "1:opt 1:(a b c)" \
+ ":opt next:(d e f)" \
+ "*:opt all:(u v w)"
+}
+```
+Explanation:
+- `1:MSG:ACTION` sets completion for the **first** optional argument
+- `:MSG:ACTION` sets completion for the **next** optional argument
+- `*:MSG:ACTION` sets completion for the optional argument where none of the
+ previous rules apply, so in our example for `arg3, argN..`.
+
> `_files` is a zsh builtin utility function to complete files/dirs see
> - [zsh completion functions][zsh-comp-fn]
> - [zsh completion utility functions][zsh-comp-utility-fn]