From bac8a5d2822835cf47175d1162030653fadd5c09 Mon Sep 17 00:00:00 2001
From: johannst Default value:Parameter
#!/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"
+ echo "flag $flag"
+ echo "o $opts[-o]"
+ echo "long $opts[--long]"
+ echo "pos $1"
}
test -f -o OPTION --long LONG_OPT POSITIONAL
@@ -361,9 +361,9 @@ The match results can be accessed via the
$MATCH
variable and
INPUT='title foo : 1234'
REGEX='^title (.+) : ([0-9]+)$'
if [[ $INPUT =~ $REGEX ]]; then
- echo "$MATCH" # title foo : 1234
- echo "$match[1]" # foo
- echo "$match[2]" # 1234
+ echo "$MATCH" # title foo : 1234
+ echo "$match[1]" # foo
+ echo "$match[2]" # 1234
fi
Completion
@@ -395,7 +395,7 @@ $words[CURRENT-1] # previous word (relative to cursor position)
MSG
simple string with header messageCOMP
array of completions where each entry is "opt:description"
COMP
array of completions where each entry is "opt:description"
function _foo() {
local -a opts
@@ -436,16 +436,16 @@ function _foo_color() {
colors+=('green:green color')
colors+=('red:red color')
colors+=('blue:blue color')
- _describe "color" colors
+ _describe "color" colors
}
function _foo() {
_arguments \
- "-c[define color]:color:->s_color" \
- "-s[select sound]:sound:(low high)" \
- "-f[select file]:file:_files" \
- "-d[select dir]:dir:_files -/" \
- "-h[help]"
+ "-c[define color]:color:->s_color" \
+ "-s[select sound]:sound:(low high)" \
+ "-f[select file]:file:_files" \
+ "-d[select dir]:dir:_files -/" \
+ "-h[help]"
case $state in
s_color) _foo_color;;
@@ -459,9 +459,9 @@ arguments such as
function _foo() {
_arguments \
- "1:opt 1:(a b c)" \
- ":opt next:(d e f)" \
- "*:opt all:(u v w)"
+ "1:opt 1:(a b c)" \
+ ":opt next:(d e f)" \
+ "*:opt all:(u v w)"
}
Explanation:
-- cgit v1.2.3