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

Strange menu selection with _arguments and matcher-list



I'm working on improving _su, mainly so that it'll call _normal on the
argument of the -c flag, the way _sh does.  I've got what I think is
a fairly straightforward _arguments call, but I get some very strange
behavior from menu selection.

Here's a relatively small test case; I haven't tried all possible smaller
cases, but it does at least appear to require multiple options that go to
the same state plus the wildcard "non-option arguments" pattern and the
"matcher-list" completion style.

Affects 4.2.5 and later, so it's not a multi-byte thing, but not 4.0.x.

----------

_foo () {
  local -A opt_args
  local -a args state context
  local line

  args=(
    '(--command)-c[pass command to shell]:command string:->command'
    '(-c)--command=-[pass command to shell]:command string:->command'
    '-f[pass -f to shell (csh)]'
    '(--login)-l[use a login shell]'
    '(-l)--login[use a login shell]'
    '(-p --preserve-environment)-m[do not reset environment]'
    '(-m --preserve-environment)-p[do not reset environment]'
    '(-m -p)--preserve-environment[do not reset environment]'
    '(--shell)-s[run the specified shell]:shell:->shell'
    '(-s)--shell=-[run the specified shell]:shell:->shell'
    '*:arguments:->rest'
  )

  _arguments -R $args[@] ||
  case $state in
    (command)
      compset -q
      _normal
      ;;
    (shell)
      compadd ${(f)^"$(</etc/shells)"}(N)
      ;;
    (rest)
      _users
      ;;
   esac
}
compdef _foo foo

zstyle ':completion:*' matcher-list '' 'r:|[-._,]=** r:|=**' 'm:{a-zA-Z}={A-Za-z} r:|[-._,]=** r:|=**' 'r:|[-._,]=** r:|=** l:|=*'
zstyle ':completion:*' completer _oldlist _expand _complete _match _ignored _approximate _prefix
zstyle ':completion:*' menu 'yes=long' 'select=9'

----------

Given the above, type

  foo anything -<TAB>

and watch strange things happen:

++++++++++
schaefer<529> foo anything --command=
--command                                      
--login                                        
--preserve-environment                         
--shell                                        
-f                                             
-c                                             
-l                                             
-p                                             
-s                                             
                                               
                                               
                                               
-m                                             
                                               
                                               
-- pass command to shell                       
-- use a login shell                           
-- do not reset environment                    
-- run the specified shell                     
-- pass -f to shell (csh)                      
--command                                      
--login                                        
--preserve-environment
++++++++++



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