From e730452fd8bd6824d35f25f2e87b8ec788b626fd Mon Sep 17 00:00:00 2001
From: Johannes Stoelp <johannes.stoelp@gmail.com>
Date: Mon, 26 Jun 2023 21:23:01 +0200
Subject: zsh: add completion example for positional args

---
 src/tools/zsh.md | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

(limited to 'src/tools')

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]
-- 
cgit v1.2.3