From faa61d5bfc0ab42ef94a75d5f392dfb9c91ce456 Mon Sep 17 00:00:00 2001 From: johannst Date: Sun, 11 Apr 2021 19:41:45 +0000 Subject: deploy: 66e190555b3570da3f547efa33f3ab89d0388582 --- print.html | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'print.html') diff --git a/print.html b/print.html index 6cb20d1..f693a68 100644 --- a/print.html +++ b/print.html @@ -295,6 +295,39 @@ echo $bar[2] # 2 echo ${(L)foo} # aabb echo ${(U)foo} # AABB +

Argument parsing with zparseopts

+
zparseopts [-D] [-E] [-A assoc] specs
+
+

Arguments are copied into the associative array assoc according to specs. +Each spec is described by an entry as opt[:][=array].

+ +
+

Documentation can be found in man zshmodules.

+
+

Example

+
#!/bin/zsh
+function test() {
+    zparseopts -D -E -A opts f=flag o: -long:
+    echo "flag $flag"
+    echo "o    $opts[-o]"
+    echo "long $opts[--long]"
+    echo "pos  $1"
+}
+
+test -f -o OPTION --long LONG_OPT POSITIONAL
+
+# Outputs:
+#   flag -f
+#   o    OPTION
+#   long LONG_OPT
+#   pos  POSITIONAL
+

Regular Expressions

Zsh supports regular expression matching with the binary operator =~. The match results can be accessed via the $MATCH variable and @@ -368,7 +401,7 @@ blu -- desc for blu FUNC call func to generate matches {STR} evaluate `STR` to generate matches -

Example

+

Example

Skeleton to copy/paste for writing simple completions.

Assume a program foo with the following interface:

foo -c green|red|blue -s low|high -f <file> -d <dir> -h
@@ -511,7 +544,7 @@ command 2>&1 >file
 
  • <param> specifies a variable name which getopts fills with the last parsed option argument
  • <args> optionally specify argument string to parse, by default getopts parses $@
  • -

    Example

    +

    Example

    #!/bin/bash
     function parse_args() {
         while getopts "f:c" PARAM; do
    @@ -582,7 +615,7 @@ compgen -W "foo foobar bar" "f"
     # compare "hom" against file/dir names and generate matches
     compgen -d -f "hom"
     
    -

    Example

    +

    Example

    Skeleton to copy/paste for writing simple completions.

    Assume a program foo with the following interface:

    foo -c green|red|blue -s low|high -f <file> -h
    @@ -1876,7 +1909,7 @@ major_pagefault: Happens when the page needed is NOT in memory, the kernel
       -l <filter> . show who calls into lib matched by <filter>
       -C .......... demangle
     
    -

    Example

    +

    Example

    List which program/libs call into libstdc++:

    ltrace -l '*libstdc++*' -C -o ltrace.log ./main
     
    -- cgit v1.2.3