aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/zsh.html
diff options
context:
space:
mode:
authorjohannst <johannst@users.noreply.github.com>2023-06-26 19:23:26 +0000
committerjohannst <johannst@users.noreply.github.com>2023-06-26 19:23:26 +0000
commit1b251a08f8c10ff292d1ca9b1c580e88df483b94 (patch)
treed208cdef5bb2029909f7f65dede1f20c25acc14e /tools/zsh.html
parenta85e47072ff808846242da49295b4b73af23b840 (diff)
downloadnotes-1b251a08f8c10ff292d1ca9b1c580e88df483b94.tar.gz
notes-1b251a08f8c10ff292d1ca9b1c580e88df483b94.zip
deploy: e730452fd8bd6824d35f25f2e87b8ec788b626fd
Diffstat (limited to 'tools/zsh.html')
-rw-r--r--tools/zsh.html23
1 files changed, 21 insertions, 2 deletions
diff --git a/tools/zsh.html b/tools/zsh.html
index 6b5eaab..04cdbde 100644
--- a/tools/zsh.html
+++ b/tools/zsh.html
@@ -378,8 +378,8 @@ blu -- desc for blu
</code></pre>
<p>where <code>SPEC</code> can have one of the following forms:</p>
<ul>
-<li><code>OPT[DESC]:MSG:ACTION</code></li>
-<li><code>N:MSG:ACTION</code></li>
+<li><code>OPT[DESC]:MSG:ACTION</code> for option flags</li>
+<li><code>N:MSG:ACTION</code> for positional arguments</li>
</ul>
<p>Available actions</p>
<pre><code class="language-zsh">(op1 op2) list possible matches
@@ -416,6 +416,25 @@ function _foo() {
esac
}
</code></pre>
+<h3 id="example-with-optional-arguments"><a class="header" href="#example-with-optional-arguments">Example with optional arguments</a></h3>
+<p>For this example we assume that the command <code>foo</code> takes at least three optional
+arguments such as</p>
+<pre><code class="language-zsh">foo arg1 arg2 arg3 [argN..]
+</code></pre>
+<pre><code class="language-zsh">function _foo() {
+ _arguments \
+ &quot;1:opt 1:(a b c)&quot; \
+ &quot;:opt next:(d e f)&quot; \
+ &quot;*:opt all:(u v w)&quot;
+}
+</code></pre>
+<p>Explanation:</p>
+<ul>
+<li><code>1:MSG:ACTION</code> sets completion for the <strong>first</strong> optional argument</li>
+<li><code>:MSG:ACTION</code> sets completion for the <strong>next</strong> optional argument</li>
+<li><code>*:MSG:ACTION</code> sets completion for the optional argument where none of the
+previous rules apply, so in our example for <code>arg3, argN..</code>.</li>
+</ul>
<blockquote>
<p><code>_files</code> is a zsh builtin utility function to complete files/dirs see</p>
<ul>