Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Incorrect use of "expl" ?



On 9 Apr, Bart wrote:
> "expl" (usually by passing to _wanted or _requested, but sometimes by
> e.g. "$expl[@]") without declaring it local.  Given that the name "expl"
> is asserted only to be a convention, most of these are probably wrong.

Yes, most are wrong. Maybe _main_complete should declare it local just
to avoid leaking it. Might also be nice to make use of private.

There are cases where we reference expl inside an _arguments spec that
uses braces - something like:
  _arguments '1:val:{ compadd "$expl[@]" words }'
That's a bit of a hack really: we're digging into what should be
_arguments internals. Perhaps we could contrive to make "$@" work
in such cases. I've left these alone.

Apart from _iftop, I didn't get too badly side-tracked on fixing other
bits of these functions. I did briefly scan them for other common errors
like $curcontext and return status.

Oliver

diff --git a/Completion/BSD/Command/_portmaster b/Completion/BSD/Command/_portmaster
index 4c16e2d1b..48390c9ad 100644
--- a/Completion/BSD/Command/_portmaster
+++ b/Completion/BSD/Command/_portmaster
@@ -5,7 +5,7 @@ _portmaster_pkgs() {
 }
 
 _portmaster_ports() {
-  local ret=1 _fbsd_ports _fbsd_cat
+  local expl ret=1 _fbsd_ports _fbsd_cat
    _fbsd_cat=(${PORTSDIR:-/usr/ports}/[a-z]*(/:t))
    if [[ $PREFIX != */* ]] ; then
      _wanted cat_packages expl 'category/ports' compadd -S '/' $_fbsd_cat
diff --git a/Completion/Debian/Command/_a2utils b/Completion/Debian/Command/_a2utils
index 46126282f..8ee30ecf1 100644
--- a/Completion/Debian/Command/_a2utils
+++ b/Completion/Debian/Command/_a2utils
@@ -1,6 +1,6 @@
 #compdef a2ensite a2dissite a2enmod a2dismod
 
-local -a mods
+local -a expl mods
 
 case "$service" in
     a2ensite)
@@ -21,4 +21,4 @@ case "$service" in
 	;;
 esac
 
-return 0
+return
diff --git a/Completion/Debian/Command/_apt b/Completion/Debian/Command/_apt
index cd0783b4f..074fb0164 100644
--- a/Completion/Debian/Command/_apt
+++ b/Completion/Debian/Command/_apt
@@ -525,7 +525,7 @@ _apt-cache () {
     --installed:bool \
     -- \
     /$'help\0'/ \| \
-    /$'add\0'/ /$'[^\0]#\0'/ ':files:index files:_files "$expl[@]"' \# \| \
+    /$'add\0'/ /$'[^\0]#\0'/ ':files:index files:_files' \# \| \
     /$'gencaches\0'/ \| \
     /$'showpkg\0'/ /$'[^\0]#\0'/ ':packages::_deb_packages "$expl_packages[@]" avail' \# \| \
     /$'showsrc\0'/ /$'[^\0]#\0'/ ':packages::_deb_packages "$expl_packages[@]" avail' \# \| \
@@ -595,10 +595,10 @@ _apt-config () {
     /$'shell\0'/ \
       \( \
 	/$'[^\0]#\0'/ ':parameters:shell variable to assign:_parameters' \
-	/$'[^\0]#\0'/ ':values:configuration key:compadd "$expl[@]" - ${${(f)"$(apt-config dump 2>&1)"}% *}' \
+	/$'[^\0]#\0'/ ':values:configuration key:compadd - ${${(f)"$(apt-config dump 2>&1)"}% *}' \
       \) \# \| \
     /$'dump\0'/ \| \
-    /"[]"/	':argument-1:action:compadd "$expl[@]" shell dump'
+    /"[]"/	':argument-1:action:compadd shell dump'
 
   _apt-config "$@"
 }
diff --git a/Completion/Debian/Command/_lighttpd b/Completion/Debian/Command/_lighttpd
index 7f4385b90..c24b42d13 100644
--- a/Completion/Debian/Command/_lighttpd
+++ b/Completion/Debian/Command/_lighttpd
@@ -1,16 +1,16 @@
 #compdef lighty-enable-mod lighty-disable-mod
 
-local -a mods
+local -a mods expl
 
 case "$service" in
     lighty-enable-mod)
 		mods=( `echo /etc/lighttpd/conf-available/*.conf(N:r:t) | sed -e 's/\b[0-9][0-9]-//g'` )
-		_wanted mods expl mods compadd -a mods
+		_wanted mods expl mod compadd -a mods
 	;;
     lighty-disable-mod)
 		mods=( `echo /etc/lighttpd/conf-enabled/*.conf(N:r:t) | sed -e 's/\b[0-9][0-9]-//g'` )
-		_wanted mods expl mods compadd -a mods
+		_wanted mods expl mod compadd -a mods
 	;;
 esac
 
-return 0
+return
diff --git a/Completion/Debian/Command/_lintian b/Completion/Debian/Command/_lintian
index 16af5085b..d60acc9ed 100644
--- a/Completion/Debian/Command/_lintian
+++ b/Completion/Debian/Command/_lintian
@@ -1,6 +1,6 @@
 #compdef lintian lintian-info
 
-local line cmds ret=1
+local curcontext="$curcontext" state line expl cmds ret=1
 
 case "$service" in
    (lintian)
@@ -55,7 +55,7 @@ case "$service" in
         (args)
           case $line[1] in
             -t|--tags)
-              _wanted tag expl 'tag' compadd $(command awk '/^Tag:/ { print $2 }' /usr/share/lintian/checks/*.desc) && ret=0
+              _wanted tags expl 'tag' compadd $(command awk '/^Tag:/ { print $2 }' /usr/share/lintian/checks/*.desc) && ret=0
             ;;
           esac
         ;;
diff --git a/Completion/Debian/Command/_wajig b/Completion/Debian/Command/_wajig
index 350eee658..26d08cfd7 100644
--- a/Completion/Debian/Command/_wajig
+++ b/Completion/Debian/Command/_wajig
@@ -1,6 +1,6 @@
 #compdef wajig
 
-local curcontext="$curcontext" state line cmds argno ret=1
+local curcontext="$curcontext" state line expl cmds argno ret=1
 
 _arguments -C -s \
   '(- 1 *)'{-h,--help}'[print usage message]' \
diff --git a/Completion/Debian/Type/_deb_architectures b/Completion/Debian/Type/_deb_architectures
index 22c43dd3e..1429112a8 100644
--- a/Completion/Debian/Type/_deb_architectures
+++ b/Completion/Debian/Type/_deb_architectures
@@ -1,6 +1,6 @@
 #autoload
 
-local extra
+local extra expl
 zparseopts -E -D -a extra a:
 
 _description architectures expl 'architecture'
diff --git a/Completion/Debian/Type/_debbugs_bugnumber b/Completion/Debian/Type/_debbugs_bugnumber
index f7b09054d..85e0c60d6 100644
--- a/Completion/Debian/Type/_debbugs_bugnumber
+++ b/Completion/Debian/Type/_debbugs_bugnumber
@@ -1,6 +1,8 @@
 #autoload
 # TODO: use _describe with some basic metadata (e.g., bug title/package/version)
 
+local expl
+
 [[ $PREFIX$SUFFIX == [0-9]# ]] || return 1
 
 # The cache directory moved; try both locations.
diff --git a/Completion/Linux/Command/_ethtool b/Completion/Linux/Command/_ethtool
index 5d607741f..71f5ed3bf 100644
--- a/Completion/Linux/Command/_ethtool
+++ b/Completion/Linux/Command/_ethtool
@@ -1,6 +1,6 @@
 #compdef ethtool
 
-local -a cmds
+local -a expl cmds
 
 if [[ $CURRENT -ge 4 ]]; then
 	case $words[CURRENT-1] in
diff --git a/Completion/Solaris/Command/_svcadm b/Completion/Solaris/Command/_svcadm
index 347e25e2a..c9826f2eb 100644
--- a/Completion/Solaris/Command/_svcadm
+++ b/Completion/Solaris/Command/_svcadm
@@ -1,7 +1,7 @@
 #compdef svcadm
 
 _svcadm() {
-	local context state line subcmds
+	local curcontext="$curcontext" state line expl subcmds
 	typeset -A opt_args
 
 	subcmds=( enable disable restart refresh mark delegate clear milestone )
diff --git a/Completion/Solaris/Command/_svccfg b/Completion/Solaris/Command/_svccfg
index 08c5e4bcd..d31682e77 100644
--- a/Completion/Solaris/Command/_svccfg
+++ b/Completion/Solaris/Command/_svccfg
@@ -14,7 +14,7 @@ _svccfg_properties() {
 	# Get all the property names for the FMRI
 	props=( ${${${(f)"$(svccfg -s $fmri describe)"}:# *}%% *} )
 
-	_multi_parts "$expl[@]" - / props
+	_multi_parts "$@" - / props
 }
 
 _svccfg() {
diff --git a/Completion/Solaris/Type/_svcs_fmri b/Completion/Solaris/Type/_svcs_fmri
index 80d3516c0..ffade6985 100644
--- a/Completion/Solaris/Type/_svcs_fmri
+++ b/Completion/Solaris/Type/_svcs_fmri
@@ -2,7 +2,7 @@
 
 _svcs_fmri() {
 	local type="$argv[$#]"
-	local fmri_abbrevs m i
+	local fmri_abbrevs m i expl
 	typeset -a -g _smf_fmris
 
 	local update_policy
diff --git a/Completion/Unix/Command/_cdrdao b/Completion/Unix/Command/_cdrdao
index 0c3cfb82e..ceb86267c 100644
--- a/Completion/Unix/Command/_cdrdao
+++ b/Completion/Unix/Command/_cdrdao
@@ -262,14 +262,14 @@ _cdrdao-copy () {
 __cdrdao-device () {
   # Use cdrdao scanbus and also check what OS we're running under and provide
   # additional stuff, like devices (/dev/sg0)
-  local -a devices
+  local -a expl devices
   devices=(${${(f)"$(_call_program devices cdrdao scanbus -v 0 2>&1)"}%% :*})
 
   _wanted devices expl 'device' compadd -a devices
 }
 
 __cdrdao-drivers () {
-  local suf
+  local expl suf
   local -Ua drivers
   drivers=(${(f)"$(_call_program drivers cut -d'\|' -f4 /usr/share/cdrdao/drivers -s)"})
   if compset -P \*:; then
diff --git a/Completion/Unix/Command/_darcs b/Completion/Unix/Command/_darcs
index d40ecda28..74734711d 100644
--- a/Completion/Unix/Command/_darcs
+++ b/Completion/Unix/Command/_darcs
@@ -13,6 +13,8 @@
 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ## GNU General Public License for more details.
 
+local expl
+
 if (($CURRENT == 2)); then
   # We're completing the first word after "darcs" -- the command.
   _wanted command expl 'darcs command' \
diff --git a/Completion/Unix/Command/_iftop b/Completion/Unix/Command/_iftop
index 41ffb4ea1..05db3fa03 100644
--- a/Completion/Unix/Command/_iftop
+++ b/Completion/Unix/Command/_iftop
@@ -1,9 +1,16 @@
 #compdef iftop
 
 _interfaces () {
-	_wanted interfaces expl 'network interface' \
-		_net_interfaces
-	_values "Pseudo-device that captures on all interfaces" "any"
+  local disp expl sep
+  _description interfaces expl 'network interface'
+  _net_interfaces "$expl[@]"
+  if zstyle -t ":completion:${curcontext}:interfaces" verbose; then
+    zstyle -s ":completion:${curcontext}:interfaces" list-separator sep || sep=--
+    disp=( "any $sep capture on all interfaces" )
+    compadd "$expl[@]" -ld disp any
+  else
+    compadd "$expl[@]" any
+  fi
 }
 
 _arguments \
@@ -14,7 +21,7 @@ _arguments \
   -P'[turn on port display]' \
   -b"[don't display bar graphs of traffic]" \
   -B'[display bandwidth rates in bytes/sec rather than bits/sec]' \
-  -i'[interface]:network interface:_interfaces' \
-  -f'[filter]:BPF filter' \
-  -F'[net/mask]:network/mask' \
-  -c'[config file]:config file:_files'
+  '-i+[interface]:network interface:_interfaces' \
+  '-f+[filter]:BPF filter' \
+  '-F+[net/mask]:network/mask' \
+  '-c+[config file]:config file:_files'
diff --git a/Completion/Unix/Command/_lha b/Completion/Unix/Command/_lha
index c2d5e7d8d..e8d47fcdb 100644
--- a/Completion/Unix/Command/_lha
+++ b/Completion/Unix/Command/_lha
@@ -1,5 +1,7 @@
 #compdef lha
 
+local expl
+
 if (( CURRENT == 2 )); then
     compset -P -
 
diff --git a/Completion/Unix/Command/_lsof b/Completion/Unix/Command/_lsof
index c12b9910a..bbb6eab59 100644
--- a/Completion/Unix/Command/_lsof
+++ b/Completion/Unix/Command/_lsof
@@ -1,6 +1,6 @@
 #compdef lsof
 
-local curcontext="$curcontext" state line fields args
+local curcontext="$curcontext" state line expl fields args
 
 case $OSTYPE in
   linux*) args=( '-X[skip reporting of info on network connections]' ) ;;
diff --git a/Completion/Unix/Command/_pkg-config b/Completion/Unix/Command/_pkg-config
index dd73c79e9..43773967e 100644
--- a/Completion/Unix/Command/_pkg-config
+++ b/Completion/Unix/Command/_pkg-config
@@ -1,6 +1,6 @@
 #compdef pkg-config
 
-local arguments packages curcontext="$curcontext" state line ret=1
+local arguments packages curcontext="$curcontext" state line expl ret=1
 declare -A opt_args
 
 # Up-to-date as of pkg-config 0.29-4 (debian package) man page synopsis
diff --git a/Completion/Unix/Command/_rrdtool b/Completion/Unix/Command/_rrdtool
index 9d097bd77..96bdaf0db 100644
--- a/Completion/Unix/Command/_rrdtool
+++ b/Completion/Unix/Command/_rrdtool
@@ -1,23 +1,25 @@
 #compdef rrdtool
 
-_arguments \
+local curcontext="$curcontext" state line expl ret=1
+
+_arguments -C \
   ':rrdtool command:(create update updatev graph dump restore
                    last lastupdate first help info fetch tune
 		   resize xport)' \
-  '*::subcmd:->subcmd' && return 0
+  '*:: :->subcmds' && ret=0
 
+curcontext="${curcontext%:*}-$words[1]:"
 case "$state" in
-    (subcmd)
-
-  case "$words[1]" in
+  (subcmds)
+    case "$words[1]" in
       (help)
-      	_wanted -V 'subcommands' expl 'subcommand' compadd \
-	create update updatev graph dump restore last lastupdate \
-	first help info fetch tune resize xport
-	;;
+	_wanted -V 'subcommands' expl 'subcommand' compadd \
+	  create update updatev graph dump restore last lastupdate \
+	  first help info fetch tune resize xport
+      ;;
       (*)
-    	_files
-    	;;
-  esac
+        _files
+      ;;
+    esac
   ;;
 esac
diff --git a/Completion/Unix/Command/_stgit b/Completion/Unix/Command/_stgit
index f313f651a..7d6ed129f 100644
--- a/Completion/Unix/Command/_stgit
+++ b/Completion/Unix/Command/_stgit
@@ -4,7 +4,7 @@ typeset -a subcmds
 
 subcmds=( ${${${(M)${(f)"$(stg help 2> /dev/null)"}## *}#  }/#(#b)([^[:space:]]##)[[:space:]]##(*)/$match[1]:$match[2]} )
 
-local curcontext="$curcontext"
+local curcontext="$curcontext" expl
 local subcmd
 local ret=1
 
@@ -18,17 +18,17 @@ else
 
   case $subcmd in
     (push)
-      _wanted -V "unapplied patches" expl "patch" \
+      _wanted -V unapplied-patches expl "patch" \
        	compadd ${${(M)${(f)"$(stg series 2> /dev/null)"}##- *}#- } \
 		&& ret=0
     ;;
     (pop)
-      _wanted -V "applied patches" expl "patch" \
+      _wanted -V applied-patches expl "patch" \
 	compadd ${${(M)${(f)"$(stg series 2> /dev/null)"}##[+>] *}#[+>] } \
 		&& ret=0
     ;;
     (edit|files|goto|rename|log|float|delete|sink|mail|sync|show|pick|hide)
-      _wanted -V "patches" expl "patch" \
+      _wanted -V patches expl "patch" \
 	compadd $(stg series --noprefix 2> /dev/null) \
 		&& ret=0
     ;;
@@ -36,7 +36,7 @@ else
       last_word="$words[$CURRENT-1]"
       refresh_patch_options=( -p --patch )
       if [[ -n ${refresh_patch_options[(r)$last_word]} ]]; then
-	_wanted -V "applied patches" expl "patch" \
+	_wanted -V applied-patch expl "patch" \
 	  compadd ${${(M)${(f)"$(stg series 2> /dev/null)"}##[+>] *}#[+>] } \
 		  && ret=0
       else
diff --git a/Completion/Unix/Command/_tcpdump b/Completion/Unix/Command/_tcpdump
index e1c38f802..79f58fe5f 100644
--- a/Completion/Unix/Command/_tcpdump
+++ b/Completion/Unix/Command/_tcpdump
@@ -53,7 +53,7 @@ _time_stamp_types () {
 }
 
 _data_link_types () {
-  local vals
+  local vals expl
   if (( $+opt_args[-i] )); then
     vals=( ${${${(s:  :)"$(_call_program data-link-types tcpdump -L -i $opt_args[-i] 2>&1)"}[2,-1]}/ /:} )
     _describe -t data-link-types "data link type ($opt_args[-i])" vals
diff --git a/Completion/Unix/Command/_texinfo b/Completion/Unix/Command/_texinfo
index 7b66d6304..57e13bdc2 100644
--- a/Completion/Unix/Command/_texinfo
+++ b/Completion/Unix/Command/_texinfo
@@ -227,7 +227,7 @@ esac
 
 if [[ -n $state ]]; then
   local chr cache file q
-  local -a suf tags
+  local -a expl suf tags
   local -i36 hash=5381
   local -aU infopath=( /usr/share/info ${commands[info]:h:h}/share/info ${(s.:.)INFOPATH} $infodirs )
   infopath=( $^infopath(N) )
diff --git a/Completion/Unix/Command/_units b/Completion/Unix/Command/_units
index d049d22ab..bea77ae67 100644
--- a/Completion/Unix/Command/_units
+++ b/Completion/Unix/Command/_units
@@ -1,6 +1,6 @@
 #compdef units
 
-local curcontext="$curcontext" state line
+local curcontext="$curcontext" state line expl
 integer ret=1
 typeset -A opt_args
 
diff --git a/Completion/Unix/Command/_yafc b/Completion/Unix/Command/_yafc
index edc7c417f..1e0a601a1 100644
--- a/Completion/Unix/Command/_yafc
+++ b/Completion/Unix/Command/_yafc
@@ -30,7 +30,7 @@ _yafc_bookmarks() {
     local bkmfile=~/.yafc/bookmarks
     
     if [[ -f $bkmfile ]]; then
-        local -a bkms
+        local -a bkms expl
         bkms=(${${${(M)"${(f)$(<$bkmfile)}":#machine*alias ##\'*\' #}##machine*alias ##\'}%%\' #}) #" vim syntax goes crazy
         _wanted bookmarks expl 'bookmarks' compadd "$@" -a - bkms
     fi
diff --git a/Completion/Unix/Type/_absolute_command_paths b/Completion/Unix/Type/_absolute_command_paths
index e08ca56df..0d52ff851 100644
--- a/Completion/Unix/Type/_absolute_command_paths
+++ b/Completion/Unix/Type/_absolute_command_paths
@@ -9,7 +9,7 @@ _hashed_absolute_command_paths() {
   do
     local -a matches=( "${(@)commands[(R)${~i}[^/]#]}" )
     local -a descs=( $matches:t )
-    compadd -M "l:|=$i" -d descs "$expl[@]" -a matches
+    compadd -M "l:|=$i" -d descs "$@" -a matches
     ret=0
   done
   return ret
diff --git a/Completion/X/Command/_setxkbmap b/Completion/X/Command/_setxkbmap
index d192cc17a..f7310ecdd 100644
--- a/Completion/X/Command/_setxkbmap
+++ b/Completion/X/Command/_setxkbmap
@@ -55,7 +55,7 @@ _setxkbmap_files () {
     local dir="$1"
     local label="$2"
 
-    local -a fullpath shortpath
+    local -a fullpath shortpath expl
 
     fullpath=($sourcedir/$dir/**/*~*README(.))
     shortpath=(${fullpath#$sourcedir\/$dir\/})
@@ -82,7 +82,7 @@ _setxkbmap_geometry () {
 (( $+functions[_setxkbmap_variant] )) ||
 _setxkbmap_variant () {
     local file=$sourcedir/symbols/${1}
-    local -a variants lines
+    local -a variants lines expl
 
     if [ ! -f $file ]; then
         _message "no such layout: ${1}"
diff --git a/Completion/X/Type/_xft_fonts b/Completion/X/Type/_xft_fonts
index 535b9b5ae..991838d67 100644
--- a/Completion/X/Type/_xft_fonts
+++ b/Completion/X/Type/_xft_fonts
@@ -1,6 +1,6 @@
 #compdef fc-list fc-match
 
-local -a suf
+local -a expl suf
 local font=${${PREFIX//-[0-9]##:/:}%:*}: ret=1
 local attr
 
diff --git a/Completion/Zsh/Command/_fc b/Completion/Zsh/Command/_fc
index 6cc01f32d..dd014e7d7 100644
--- a/Completion/Zsh/Command/_fc
+++ b/Completion/Zsh/Command/_fc
@@ -1,6 +1,6 @@
 #compdef fc history r
 
-local curcontext="$curcontext" state state_descr line ret=1
+local curcontext="$curcontext" state state_descr line expl ret=1
 local num cmd sep
 local -a events
 typeset -A opt_args
diff --git a/Completion/Zsh/Context/_value b/Completion/Zsh/Context/_value
index 47fbc1749..22372ab36 100644
--- a/Completion/Zsh/Context/_value
+++ b/Completion/Zsh/Context/_value
@@ -24,6 +24,7 @@ else
   if [[ "$compstate[parameter]" != *-* &&
         "$compstate[context]" = *value &&
         "${(Pt)${compstate[parameter]}}" = assoc* ]]; then
+    local expl
     if (( CURRENT & 1 )); then
       _wanted association-keys expl 'association key' \
           compadd -k "$compstate[parameter]"
diff --git a/Completion/Zsh/Function/_add-zle-hook-widget b/Completion/Zsh/Function/_add-zle-hook-widget
index 93954a2bb..f108d1868 100644
--- a/Completion/Zsh/Function/_add-zle-hook-widget
+++ b/Completion/Zsh/Function/_add-zle-hook-widget
@@ -11,6 +11,7 @@ _add-zle-hook-widget_types() {
 }
 
 _add-zle-hook-widget_widgets() {
+  local expl
   if (( $+opt_args[-d] )); then
     local -a tmp
     zstyle -g tmp $line[1] widgets
diff --git a/Completion/Zsh/Function/_add-zsh-hook b/Completion/Zsh/Function/_add-zsh-hook
index fb5403a60..e8ae97052 100644
--- a/Completion/Zsh/Function/_add-zsh-hook
+++ b/Completion/Zsh/Function/_add-zsh-hook
@@ -1,6 +1,7 @@
 #compdef add-zsh-hook
 
 _add-zsh-hook_hooks() {
+  local expl
   if (( $+opt_args[-d] )); then
     _wanted functions expl "installed hooks" compadd -a - "$line[1]_functions" && return 0
   else



Messages sorted by: Reverse Date, Date, Thread, Author