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

Re: psychiatric help



On Sun, Apr 5, 2026 at 10:28 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> Tried this:
>
> alias tt='noglob _tt'
> function _tt ()
> {
> out=( $@ )                # Bart sez.  Array will preserve hard space, no backslash needed.
> _execute 'ls $~out'    # Need tilde here!

This is a bit inside-out if not exactly backward.  Please note that:
1)  $~out does nothing here because of the single quotes around it.
2) The presence of the tilde has an effect later only because
> ... '_execute' boils down to a call to 'eval' as you suspect ...
3) None of that would be necessary if you weren't prefixing with noglob

Hunting back through some of your old posts, I'm reminded that your _l
function wants to rewrite the not-yet-globbed command into something
else, and _execute is just an adjunct to put the rewrite into the
history.  Without doing a lot more historical research than I want to,
I don't know why it was never made clear before that this is the wrong
place to go about this ... your instinct about studying the other
approaches ("A ZLE widget for calculator" thread) was a good one.

There's a bunch of stuff in the calculator thread about writing only
the unmodified command into the history, whereas you appear to want
the rewritten command in the history (or maybe you want both?).  I'll
address the simpler case of keeping only the rewritten command.

Start this way:

1) Edit your _l function to expect to be a ZLE widget:
    a) add a few lines at the top:
      set -- ${(z)BUFFER}
      [[ ${aliases[$1]} = 'noglob _l' ]] || return 0
      shift # discard command word, to be replaced by ls
    b) replace call to _execute with assignment to BUFFER
      _execute 'ls $~out' # would become something like
      BUFFER="ls $out" # No need for single-quotes or tilde, I think
2) Install the new function as a widget
    zle -N zle-line-finish _l

There may be some other details depending on what happens in _l but
that's the gist of it.  Note this only works when _l is NOT embedded
in some more complex command, but I think you said before that is not
an issue.  I couldn't find any details of _l shared before, or I'd
have made more specific suggestions.




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