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

Re: psychiatric help



On Sun, Apr 5, 2026 at 4:41 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> Here's why I want to capture the 'tail' literally:

Yes, I got that.

> Thus the tweedle dum and tweedle dee of 'noglob' and 'eval' ... and thus
> these silly issues.  If I could access the BUFFER (or wherever) and grab
> the command AS TYPED into some variable

Did you even read what I wrote after "Start this way:" in the previous post?

The place you can access $BUFFER is in the zle-line-finish widget.  At
this point globbing (and other expansion including aliasing) has not
happened yet.

After rewriting to the "nauseating to look at" representation, you can
then put that nauseating thing back into BUFFER, as long as you're
still in the zle-line-finish widget.

And then zsh will put the unexpanded thing into the history (whether
that's the original BUFFER or the nauseating rewrite), and afterwards
glob it etc. for actual execution.  You no longer need to force the
history with print -rS nor to pass the whole thing to eval -- you've
instead changed what ZLE will send to be executed.

You just have to do a little bit of work to turn the guts of your _l
function into something that will work as a user-defined widget.  I
tried to give some hint as to how to go about doing that with as few
changes as possible.

Let me try demonstrating with your simpler example:

function _tt ()
{
  set -- ${(z)BUFFER}    # Widget doesn't get $@, so create it for clarity
  # Next line replaces alias tt='noglob _tt' but see users/30496
  [[ $1 = tt ]] || return 0  # Don't mess with other commands
  shift                  # This throws away "tt" leaving only the "tail"
  out=( $@ )             # Not really needed, but to keep the example
  out=( '(#i)'$^out )    # Prefix every tail with ignore-case
  BUFFER="ls -AFrGgdt $out"  # Put it back together with "ls" in front
  # All done, no need for _execute
}
zle -N zle-line-finish _tt

Try that and observe the result.




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