Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: psychiatric help
- X-seq: zsh-users 30502
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: psychiatric help
- Date: Mon, 6 Apr 2026 09:43:30 -0700
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=voL9eHJXkdxrwlHExGMpn2YK35jO0Dlo/96492sDOaY=; fh=yk3c4scJWo86Za4IR1HBNZw2a+GkUkfVQ7Fs3jnanfg=; b=JzlpQUtcWAoU3wjEUAYY3RardnOa5bIM0aftYbhi+96Ul/nLJ8DdIlvMmJaXz5oPG5 SJKG/kfGgDGUT4Ds4tbRenp8AVfN78HBFCYLEzlgf0GDUxupiS6o4meuqeLKlTISN3x/ 8+XKS1hNfOhdQZVHMNepGOF/d1AZIxWkdLDa8BOIZrfYaRBMuqOFcJRnGApqE+BQ6jHu AocPYYOUFaP4XIzrKnmHxZ0UrwjHsdaPLBBOMQ70pVspl++KUR1kR8P+7pymBgYcgkB8 j5NCX2j5rxJavv3FQsR7/zyX/GYZlfVqz6br585V3Gc8QET9OdrnCfXg18Y/S+sX61ha Ck+Q==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1775493823; cv=none; d=google.com; s=arc-20240605; b=dfPtrvzXiQI8aDxf2sgwZpwIUvQnXN+71AaymgwfMHZXxdpepbs30PJa4t8egojbUP LsK66hI4A+KvqQf47oZJjQnafTFQ2iG6ZdOl1/L/kkV2I63GqK1jslj46cMiXryHAwDs C5ib7DslunJMPcmPPDnXFiCnHL2pwFIvpKtSeNQkbkh6sEE7kCKf2xF4ucYkDloov9OK DjhB8kFGjjnDiFsC8qEMv2KDQfRFjcZqYLTag21+BNZKbhdDz0mO+Odug81qfAXPdAry H5gCPyFa3dSzS17yO/EZ/62e/Cu/AMMfHozIUm17ncLEwtOOkVIvTrDW+/DzCvar0FXK U7Ow==
- Archived-at: <https://zsh.org/users/30502>
- In-reply-to: <00200287-37cf-4c9e-a3fa-0cd1d3eb0525@eastlink.ca>
- List-id: <zsh-users.zsh.org>
- References: <0610849d-f81c-4539-b13d-c4be9cbd1276@eastlink.ca> <CAA=-s3yUhzu7WbAB0F09abwmzPYowJ1s6o+YiV+cuQBf-GvFXw@mail.gmail.com> <448d6d35-c261-4e7e-bc67-c2a58d082b87@eastlink.ca> <CAA=-s3wKQb+1Sq2mV+h2Gk8rOQYKt8x_JNg9NhmdwAgJesxBkQ@mail.gmail.com> <755f4aa9-e27a-4b4d-8f23-add76a13ee83@eastlink.ca> <CAH+w=7Ydks9vqHA8x_zcHq454q8_C49Tq0xqPWuv9ejKYxCoOA@mail.gmail.com> <fcd552e0-d0eb-4443-bf6a-8ba11663638f@eastlink.ca> <CAH+w=7aksiqTuN4A_203YDWd9RfBwq2X83Oo9z0=45Md6aeWSg@mail.gmail.com> <e2d7c5e8-b994-4f38-8396-c21d493a617b@eastlink.ca> <CAH+w=7abnQZxhPc8AfsOxenKFL5tWce9A52GXv7m9rHh5eXHGw@mail.gmail.com> <d0c21ec7-832b-4ac5-a855-4b914827c61d@eastlink.ca> <CAH+w=7bW3Y921rXQmWvKT03Jv25T+o_FQOjk2VdHTnrq2+abAQ@mail.gmail.com> <00200287-37cf-4c9e-a3fa-0cd1d3eb0525@eastlink.ca>
On Mon, Apr 6, 2026 at 7:18 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> On 2026-04-05 22:03, Bart Schaefer wrote:
> > zle-line-finish is a "special" widget that ZLE runs automatically just
> > after accept-line (the widget normally bound to Enter/Return). By
> > default it's not defined at all, so you have to create it.
> Ah! Like preexec() -- IF it exists it will be executed. Yes?
Yes.
> > zle -N zle-line-finish _tt
> > Like that.
> Not to split hairs, but does that append _tt or cause _tt to be absorbed
> into zle-line-finish?
Ir replaces zle-line-finish with _tt. There's another mechanism
called "hooks" for chaining together a series of functions all run at
the time of the zle-line-finish event, but get your head around the
single function first.
> As you say, the latter doesn't exist, so this
> creates it but with the contents of _tt? But zle-line-finish can't be
> found even after the above is executed.
You're probably looking in the wrong place. Widgets aren't in the
same namespace as shell functions. To see the widget, use
% zle -l
zle-line-finish (_tt)
> function ttt ()
> {
> BUFF=${(z)BUFFER} # I just need access, I don't need it actually on the CL.
Er, no. (z) creates an array, if you're going to assign it as a
scalar you would just do
BUFF=$BUFFER
but what you really want is
BUFF=( ${(z)BUFFER} )
> export BUFF
BUFF is already a global (because you didn't declare it local). You
don't want or need to export it.
> }
> zle -N zle-line-finish ttt
If that's all you're going to do you might as well stick with precmd.
The point of using zle-line-finish would be to eventually assign
something back to BUFFER again.
> alias l='noglob _l'
> function _l ()
> {
> echo "\nMy name is $BUFF[1]
> and my unexpanded tail is: ${BUFF[2,-1]}"
This will work if BUFF is an array, but not when it's a scalar.
> ... when I first threw myself at this issue, the simple idea was to just
> retrieve the command line from history:
>
> $ history -rn -1
>
> ... but the line in history and the above $BUFF method have the exactly
> same problem, namely when there's more than one command on the line.
You're asking for two mostly-incompatible things. ZLE and history can
be thought of as both working on units of user input, "tails" are in
units of individual commands.
> The real goal here is to get the unexpanded tail of each command
> separately. But perhaps zsh expands the whole line in one go rather
> than first break the line into separate commands, and then do the
> expansion?
It's a lot more complicated than this, but you can think of it as
1) Accept the input from the current prompt
2) Expand all the aliases
3) Repeat:
a) Gather everything up to a command separator
b) Expand all the globs and variables
c) Run the command from the first word
You are looking for a cross of what's just after (1) with what's just
after (3a), except that you want to access it in the middle of (3c).
That doesn't exist anywhere. When there's only a single command, you
can fake it by looking at the "tail" of $BUFFER, but if you want it
for a complex command you're on your own to repeat the equivalent of
(3a) on the contents of $BUFFER to pick out the individual "tails"
before you reach (2).
Your current hack uses "noglob" at (2) to bypass some of (3b) and then
"eval" inside (3c) to run a different command than what appeared at
(1). That may be the best you can do, but as you've noted it tends to
be fragile around quoting and doesn't really get you exactly what
you're seeking.
> Unless ... each command sequentially bit off its own chunk of $BUFF, up
> to the semicolon, leaving the next command unambiguously looking at the
> next: 'command' 'tail' 'semicolon'. Should be easy?
You're implementing a shell command parser in shell commands. Ask the
folks who implemented zsh syntax highlighting in ZLE how easy that
was.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author