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

[BUG?] Unexpected behaviour with `compdef -p`



I was trying to use `compdef -p` to avoid having to list out a large number of
commands i want to complete that all have the same prefix, and i found that it
doesn't really work the way i expected — it destroys the completion output.

Example (with completion loaded obv, and i have menu selection on in my case):

  % cat _xyz
  _arguments -s -S : {-h,--help}'[display help information]'
  % fpath=( $PWD $fpath )
  % autoload -Uz _xyz
  % compdef _xyz -p 'xyz*'
  % xyzabc -<TAB>
  completing option:
  --help
  -h
    display help information
  --help
  -h
    display help information
  --help
  -h
    display help information
  <... and so on; the output is essentially garbage>

When i use -P instead of -p, the output is as expected.

Mikael had the following to say when i brought it up on IRC:

  < Mikachu> i guess it ends up calling the completer two times
  < Mikachu> -p is tried "before other completions"
  < Mikachu> okdana: if i do the compdef _xyz -P xyz\* then
  < Mikachu> xyz <tab> will show just -h and --help
  < Mikachu> if i do -p instead, then xyz <tab> shows -h and --help correctly
             but also completes files
  < Mikachu> if i do xyz -<tab> then it shows the bogus output
  < Mikachu> so yeah, with -p you call your completer, then the default
             completer list is tried in some weird way, and then the completer
             gets called again by the normal path
  < Mikachu> i don't know if any of that is intended
  < Mikachu> (i also made sure to use compdef -d -p xyz\* etc between each test)

I am not that familiar with the part of the completion system that deals with
this. Is the above in fact the intended behaviour? (If it is, what scenario
would one use -p in where it wouldn't cause these problems?)

dana



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