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

matching commands by pattern



Howdy list!

Due to a question in comp.unix.shell, I recently thought about the
following:

I'm trying to be able to use compsys to find all completions, that are
possible as the first word of the command-line _and_ match a given
pattern. Ideally, these matches should be accessible via a completion
menu.

E.g.:

% *com*<KEY-SEQUENCE>
- external command -
combine                  compose
comm                     composeglyphs
compare                  composite
compile_et               debcommit
- builtin command -
command                  comparguments
compadd                  compcall
- shell function -
compaudit                compdef
- alias -
which-command
- parameter -
commands
- original -
*com*

The solution I found is this:
[snip]
zmodload zsh/complist
autoload -U compinit && compinit
zstyle ':completion:::::' completer _complete _match
zstyle ':completion:*:descriptions' format "- %d -"
zstyle ':completion:*:default' list-prompt '%S%M matches%s'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select
bindkey "^xd" menu-complete
[snap]

That way, I can enter a pattern (like *com*) and hit 'ctrl-x d' to get
into a nice menu with possible completions.

My questions are:
Is this the way one would do it?
Is there a possibility, to get this going with 'expand-or-complete'
instead of 'menu-complete'? That way you could use <TAB> to trigger
the menu. I think this could be done by not expanding filenames, if
completing the first word in the command-line. But I'm not sure, how
to achieve this.

Any comments are welcome.

Regards, Frank



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