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

Re: matching commands by pattern



Peter Stephenson <pws@xxxxxxx>:
> Frank Terbeck wrote:
> > 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.
> 
> It's easy: just set the option "globcomplete", that's what it's designed
> for.  This makes pattern characters active during normal completion, so
> you don't have to do anything else special to get command completion in
> command position.

Thank you, Peter.

This works. But it this way, glob_complete is in effect for every glob
on the command-line when trying to complete.

% ls *.txt<TAB>

drops into a menu, rather than expanding the glob into .txt files.
Would it be possible to enable glob_complete only for the 1st word on
the line other then the following code?

[snip]
function _mycomp () {
  setopt localoptions;
  local buf
  buf=(${(s: :)LBUFFER})                                                                                                                                        if [[ ${#buf} -eq 1 ]] ; then
    setopt globcomplete;
  else
    setopt noglobcomplete;
  fi
  zle expand-or-complete
}
zle -N _mycomp
bindkey "^I" _mycomp
[snap]

Regards, Frank



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