From: Bart Schaefer <schaefer@brasslantern.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: zsh-users@zsh.org
Subject: Re: "Pull just the text of a single command" (was Re: .zsh_history)
Date: Sun, 16 Apr 2023 08:53:06 -0700 [thread overview]
Message-ID: <CAH+w=7bZfwGgKeznLdHK+ZWXbHo0w=H+HAsEac+kZ-8iBLKuBA@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7b3V06phpyR3-nr1HCfnquFZtNFVrenbf+yr=8ViZ9v0w@mail.gmail.com>
[Bringing in other responses from the "was Re:" thread]
On Sun, Apr 16, 2023 at 7:53 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> On 2023-04-16 00:38, Roman Perepelitsa wrote:
> > On Sat, Apr 15, 2023 at 5:31 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
> >> $ my_function $path $(eval 'ls *') one two three ! < > ``.."" &>^!
> >>
> >> my tail, exactly as typed, is: $path $(eval 'ls *') one two three ! < >
> >> ``.."" &>^!
> > What would this do?
> >
> > % list=(my_function arg)
> > % $list
> >
> > What I typed is `$list`, but what is "tail"?
> >
> > Roman.
>
> I don't understand. You're assigning a variable no?
Right, you don't understand. Roman's point is that
% $list
is going to run "my_function arg" as a command, so there's nothing in
"its tail as raw keystrokes" that corresponds to what "my_function"
will receive in its positional parameters. The assignment is just
setting up the case of interest.
If Roman had written
% list=$(my_function arg)
then your follow-up would be closer to the mark, because then
my_function would actually run during the assignment instead of during
the expansion of $list.
> There's just that: "% echo one; echo two; echo> three" problem -- I'd like the middle 'echo' to know that it's tail is
> 'two' and nothing more or nothing less but of course recall from history
> gives all three commands in one serving.
It's much worse than that, consider
% my_function one && my_function $PATH || my_function three > filename
Or pipelines, or backgrounding, or if/then/else/fi, etc. You will
need to define what you intend in each case (please, not by writing it
in prose here).
The ${(z)...} expansion does a best-case job of mimicking the parser,
so you can start by using ${(z)1} in preexec and work forward from
there. The simple case with semicolons can be handled by
chain=( ${(s:; :)${(z)1}} )
next prev parent reply other threads:[~2023-04-16 15:53 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-08 16:16 .zsh_history Perry Smith
2023-04-08 16:53 ` .zsh_history Roman Perepelitsa
2023-04-08 17:23 ` .zsh_history Ray Andrews
2023-04-08 17:27 ` .zsh_history Roman Perepelitsa
2023-04-08 17:35 ` .zsh_history Perry Smith
2023-04-08 17:54 ` .zsh_history Ray Andrews
2023-04-14 14:36 ` .zsh_history Felipe Contreras
2023-04-14 15:27 ` .zsh_history Ray Andrews
2023-04-15 4:49 ` .zsh_history Felipe Contreras
2023-04-15 15:29 ` .zsh_history Ray Andrews
2023-04-15 19:47 ` "Pull just the text of a single command" (was Re: .zsh_history) Bart Schaefer
2023-04-15 22:47 ` Ray Andrews
2023-04-15 23:26 ` Bart Schaefer
2023-04-16 15:53 ` Bart Schaefer [this message]
2023-04-16 16:37 ` Ray Andrews
2023-04-16 19:24 ` Ray Andrews
2023-04-16 7:38 ` .zsh_history Roman Perepelitsa
2023-04-16 14:53 ` .zsh_history Ray Andrews
2023-04-16 15:28 ` .zsh_history Bart Schaefer
2023-04-16 15:29 ` .zsh_history Roman Perepelitsa
2023-04-14 14:28 ` .zsh_history Felipe Contreras
2023-04-14 15:18 ` .zsh_history Ray Andrews
2023-04-14 14:00 ` .zsh_history Felipe Contreras
2023-04-14 14:51 ` .zsh_history Felipe Contreras
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH+w=7bZfwGgKeznLdHK+ZWXbHo0w=H+HAsEac+kZ-8iBLKuBA@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=rayandrews@eastlink.ca \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).