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

Re: Zsh completion configuration



On Feb 25,  2:47pm, joe M wrote:
} 
} I am trying to figure out how to add "history-words" as a group within
} _complete, similar to aliases or functions.
} 
} But, I could not figure out what compadd does from the zsh source. Any
} thoughts on what compadd does, or, how I can add another tag to the
} list of tags suggested by _command_names?

Unless I'm misunderstanding your intent, you don't actually want to
change the tags from _command_names -- you just want to add another tag
that appears in completion output along with the _command_names tags?

To do this you want to replace the completer function for "-command-"
context.  By default this is the _autocd completer (which is only the
default because _autocd is the only file in the completion library that
begins with "#compdef -command-").

So first make yourself a little function patterned on _autocd:

    _history_or_autocd () {
      _history
      local ret=$?
      _autocd || return ret
    }

And then install it for the context:

    compdef _history_or_autocd -command-

To explain a bit further, the completers in the completer style are in
general attempted until one returns a zero (true, success) status, at
which point the set of possible matches is assumed to be finished.  To
merge the results of several completers you have to save the staus, try
the next one, and then return success if any of those completers was
successful.

If you instead wanted to complete history and only try the defaults if no
history words matched, you could have shortcut this as

    compdef '_history || _autocd' -command-

Of course whichever of these you choose has to happen after compinit is
run, otherwise _autocd will step on it when loaded.



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