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

Re: Tip of the day: previous command output



On Sun, 22 Aug 2004, Vincent Lefevre wrote:

> I mean that instead of expanding to filenames, one expands
> to lines from $kept (but only those that match the pattern).

Aha.  So, akin to the case where you've provided a prefix, but instead 
you've provided a pattern.

This is almost exactly the same as the _insert_kept widget, so I'll just
edit it to include a test on the $WIDGET name.  Like so:

  _insert_kept() {
    (( $#kept )) || return 1
    local action
    zstyle -s :completion:$curcontext insert-kept action
    if [[ -n $action ]]
    then compstate[insert]=$action
    fi
    if [[ $WIDGET = *expand* ]]
    then compadd -U ${(M)kept:#${~words[CURRENT]}}
    else compadd -a kept
    fi
  }
  zle -C insert-kept-result complete-word _generic
  zle -C expand-kept-result complete-word _generic
  zstyle ':completion:*-kept-result:*' completer _insert_kept

This obviously isn't as sophisticated as _expand, which knows how to deal 
with all sorts of things besides just patterns.  You might also find that
the call to compadd -U needs to have some of the -i -I -P -S options 
thrown in to avoid obliterating parts of the word that you didn't mean
to obliterate; I've shown only the most simple solution.



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