aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/zsh.html35
1 files changed, 34 insertions, 1 deletions
diff --git a/tools/zsh.html b/tools/zsh.html
index eff4a16..e1fc9f1 100644
--- a/tools/zsh.html
+++ b/tools/zsh.html
@@ -276,6 +276,39 @@ echo $bar[2] # 2
echo ${(L)foo} # aabb
echo ${(U)foo} # AABB
</code></pre>
+<h2><a class="header" href="#argument-parsing-with-zparseopts" id="argument-parsing-with-zparseopts">Argument parsing with <code>zparseopts</code></a></h2>
+<pre><code class="language-zsh">zparseopts [-D] [-E] [-A assoc] specs
+</code></pre>
+<p>Arguments are copied into the associative array <code>assoc</code> according to <code>specs</code>.
+Each spec is described by an entry as <code>opt[:][=array]</code>.</p>
+<ul>
+<li><code>opt</code> is the option without the <code>-</code> char. Passing <code>-f</code> is matched against <code>f</code>
+opt, <code>--long</code> is matched against <code>-long</code>.</li>
+<li>Using <code>:</code> means the option will take an argument.</li>
+<li>The optional <code>=array</code> specifies an alternate storage container where this
+option should be stored.</li>
+</ul>
+<blockquote>
+<p>Documentation can be found in <code>man zshmodules</code>.</p>
+</blockquote>
+<h3><a class="header" href="#example" id="example">Example</a></h3>
+<pre><code class="language-zsh">#!/bin/zsh
+function test() {
+ zparseopts -D -E -A opts f=flag o: -long:
+ echo &quot;flag $flag&quot;
+ echo &quot;o $opts[-o]&quot;
+ echo &quot;long $opts[--long]&quot;
+ echo &quot;pos $1&quot;
+}
+
+test -f -o OPTION --long LONG_OPT POSITIONAL
+
+# Outputs:
+# flag -f
+# o OPTION
+# long LONG_OPT
+# pos POSITIONAL
+</code></pre>
<h2><a class="header" href="#regular-expressions" id="regular-expressions">Regular Expressions</a></h2>
<p>Zsh supports regular expression matching with the binary operator <code>=~</code>.
The match results can be accessed via the <code>$MATCH</code> variable and
@@ -349,7 +382,7 @@ blu -- desc for blu
FUNC call func to generate matches
{STR} evaluate `STR` to generate matches
</code></pre>
-<h3><a class="header" href="#example" id="example">Example</a></h3>
+<h3><a class="header" href="#example-1" id="example-1">Example</a></h3>
<p>Skeleton to copy/paste for writing simple completions.</p>
<p>Assume a program <code>foo</code> with the following interface:</p>
<pre><code class="language-zsh">foo -c green|red|blue -s low|high -f &lt;file&gt; -d &lt;dir&gt; -h