mirror of git://git.code.sf.net/p/zsh/code
32997: new utility function for separated lists
This commit is contained in:
parent
5bcf00979f
commit
469ee6daef
|
@ -1,3 +1,10 @@
|
|||
2014-08-14 Oliver Kiddle <opk@zsh.org>
|
||||
|
||||
* 32997: Completion/Base/Utility/_sequence, Doc/Zsh/compsys.yo,
|
||||
Completion/Unix/Command/_mount, Completion/Unix/Command/_nmap,
|
||||
Completion/Unix/Command/_pgrep, Completion/Unix/Command/_zip:
|
||||
add completion utility function for lists
|
||||
|
||||
2014-08-14 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* 33002: Doc/Zsh/tcpsys.yo, Functions/TCP/tcp_expect: add option
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
#autoload
|
||||
|
||||
# a separated list where each component of the list uses the same
|
||||
# function.
|
||||
|
||||
# -n num : number of items in list [default is unlimited]
|
||||
# -s sep : specify separator [defaults to comma]
|
||||
# -d : duplicate values allowed
|
||||
|
||||
local curcontext="$curcontext" nm="$compstate[nmatches]" pre nosep minus
|
||||
local -a sep num pref suf end uniq dedup
|
||||
|
||||
zparseopts -D -a opts s:=sep n:=num p:=pref i:=pref P:=pref I:=suf S:=suf q=suf r:=suf R:=suf C:=cont d=uniq M: J: X: x:
|
||||
(( $#cont )) && curcontext="$curcontext%:*}:$cont[2]"
|
||||
(( $#sep )) || sep[2]=,
|
||||
|
||||
if (( $+suf[(r)-S] )); then
|
||||
end="${(q)suf[suf[(i)-S]+1]}"
|
||||
(( $#end )) && compset -S ${end}\* && suf=() && nosep=1
|
||||
fi
|
||||
|
||||
if (( ! $#uniq )); then
|
||||
(( $+pref[(r)-P] )) && pre="${(q)pref[pref[(i)-P]+1]}"
|
||||
typeset -T unique="${PREFIX#$pre}" uniq $sep[2]
|
||||
dedup=( ${(q)uniq[1,-2]} )
|
||||
unique="${SUFFIX}"
|
||||
dedup+=( ${(q)uniq[2,-1]} )
|
||||
fi
|
||||
|
||||
if (( ! $#num )) || (( num[2] > 1 )) && ! compset -P $(( num[2] - 1 )) \*$sep[2]; then
|
||||
(( nosep )) || suf=( -S $sep[2] -r "$end[1]${sep[2][1]} \t\n\-" )
|
||||
compset -S ${sep[2]}\* && suf=()
|
||||
compset -P \*$sep[2] && pref=()
|
||||
else
|
||||
pref=()
|
||||
fi
|
||||
|
||||
(( minus = argv[(ib:2:)-] ))
|
||||
"${(@)argv[1,minus-1]}" "$opts[@]" -F dedup "$pref[@]" "$suf[@]" "${(@)argv[minus+1,-1]}"
|
|
@ -688,7 +688,7 @@ if [[ "$service" = mount ]]; then
|
|||
"($excl -r -w --rw)"{-w,--rw}'[mount read/write]'
|
||||
"($excl)-L+[mount partition with specified label]:label:->labels"
|
||||
"($excl)-U+[mount partition with specified uuid]:uuid"
|
||||
"($excl -t --types)"{-t+,--types=}'[specify file system type]:file system type:->fslist'
|
||||
"($excl -t --types)"{-t+,--types=}'[specify file system type]:file system type:_sequence -s , _file_systems'
|
||||
"($excl -O --test-opts)"{-O+,--test-opts=}'[with -a, restrict filesystems by options]:file system option:->fsopt'
|
||||
"($excl -a -O -o --options)"{-o+,--options=}'[specify file system options]:file system option:->fsopt'
|
||||
'(: -)'{-B,--bind}'[remount part of filesystem elsewhere]:old directory:_directories:new directory:_directories'
|
||||
|
@ -743,7 +743,7 @@ if [[ "$service" = mount ]]; then
|
|||
'-o[specify file system options]:file system option:->fsopt'
|
||||
'-p[print mounted file systems]'
|
||||
'-r[mount readonly]'
|
||||
'-t[specify file system type]:file system type:->fslist'
|
||||
'-t[specify file system type]:file system type:_sequence -s, _file_systems'
|
||||
'-u[change status of already mounted filesystem]'
|
||||
'-v[verbose mode]'
|
||||
'-w[mount read/write]'
|
||||
|
@ -817,7 +817,7 @@ else
|
|||
'-A[unmount all mounted file systems except the root]'
|
||||
'-f[force unmount]'
|
||||
'-h[unmount all filesystems associated with host]:host:_hosts'
|
||||
'-t[unmount all filesystems of specified type]:file system type:->fslist'
|
||||
'-t[unmount all filesystems of specified type]:file system type:_sequence -s, _file_systems'
|
||||
'-v[verbose mode]'
|
||||
'*:dev or dir:->udevordir'
|
||||
)
|
||||
|
@ -846,11 +846,6 @@ else
|
|||
fi
|
||||
|
||||
case "$state" in
|
||||
fslist)
|
||||
compset -P '*,'
|
||||
compset -S ',*' || suf=','
|
||||
_file_systems -qS "$suf"
|
||||
;;
|
||||
fsopt)
|
||||
_tags options || return 1
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ _arguments -C \
|
|||
'-iR[scan random hosts]:num hosts' \
|
||||
'-p[specify ports to try]:port numbers' \
|
||||
'-F[scan only ports listed in services file]' \
|
||||
'-D[perform decoy scan]:host list:->host-list' \
|
||||
'-D[perform decoy scan]:host list:_sequence -s, _hosts' \
|
||||
'-S[specify source address]:address:_hosts' \
|
||||
'-e[specify interface to use]:network interface:_net_interfaces' \
|
||||
'-g[specify source port number]:port number' \
|
||||
|
|
|
@ -70,13 +70,9 @@ _arguments -s -w $arguments && ret=0
|
|||
|
||||
case $state in
|
||||
(tty)
|
||||
compset -P '*,'
|
||||
|
||||
local -a used ttys
|
||||
used=(${(s:,:)IPREFIX})
|
||||
|
||||
local -a ttys
|
||||
ttys=( /dev/tty*(N) /dev/pts/*(N) )
|
||||
_wanted tty expl 'terminal device' compadd -S ',' -q -F used ${ttys#/dev/}
|
||||
_sequence -s , _wanted tty expl 'terminal device' compadd - ${ttys#/dev/}
|
||||
;;
|
||||
|
||||
(sid)
|
||||
|
|
|
@ -104,11 +104,8 @@ fi
|
|||
|
||||
case $state in
|
||||
suffixes)
|
||||
compset -P '*:'
|
||||
compset -S ':*' || suf=":."
|
||||
suffixes=( *.*(N:e) )
|
||||
_wanted suffixes expl suffixes \
|
||||
compadd -S "$suf" -r ": \t" .$^suffixes && return
|
||||
_sequence -s : _wanted -x suffixes expl suffix compadd - .$^suffixes && return
|
||||
;;
|
||||
files)
|
||||
if [[ $service = zip ]] && (( ! ${+opt_args[-d]} )); then
|
||||
|
|
|
@ -4741,6 +4741,19 @@ This function accepts the tt(compadd) options `tt(-V)', `tt(-J)',
|
|||
`tt(-r)', `tt(-R)', and `tt(-q)' and passes them on to the tt(compadd)
|
||||
builtin used to add the matches.
|
||||
)
|
||||
findex(_sequence)
|
||||
item(tt(_sequence) [ tt(-s) var(sep) ] [ tt(-n) var(max) ] [ tt(-d) ] var(function) [ tt(-) ] ...)(
|
||||
This function is a wrapper to other functions for completing items in a
|
||||
separated list. The same function is used to complete each item in the
|
||||
list. The separator is specified with the tt(-s) option. If tt(-s) is
|
||||
omitted it will use `tt(,)'. Duplicate values are not matched unless
|
||||
tt(-d) is specified. If there is a fixed or maximum number of items in
|
||||
the list, this can be specified with the tt(-n) option.
|
||||
|
||||
Common tt(compadd) options are passed on to the function. It is possible
|
||||
to use tt(compadd) directly with tt(_sequence), though tt(_values) may
|
||||
be more appropriate in this situation.
|
||||
)
|
||||
findex(_setup)
|
||||
item(tt(_setup) var(tag) [ var(group) ])(
|
||||
This function sets up the special
|
||||
|
|
Loading…
Reference in New Issue