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

Re: Tip of the day: previous command output



On Fri, 20 Aug 2004, Bart Schaefer wrote:

> I won't try to test this, but something like this should do it:

OK, I lied.  I tested it.  It didn't do what I expected, though it did 
what I told it to do.

Here's a version that actually does what was asked:

  _expand_word_and_keep() {
    function compadd() {
      local -A args
      zparseopts -E -A args J:
      if [[ $args[-J] == all-expansions ]]
      then
        builtin compadd -A kept "$@"
        kept=(${(Q)${(z)kept}})
      fi
      builtin compadd "$@"
    }
    local result
    _main_complete _expand
    result=$?
    unfunction compadd
    return result
  }

With 4.2.1, you can replace the five "local ... return" lines with

    { _main_complete _expand } always { unfunction compadd }

Left as an excercise:  Get the name of the "keep" variable from a zstyle,
so you can stash expansions in different places depending on context.



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