zsh-users
 help / color / mirror / code / Atom feed
* Unexpected results
@ 2022-08-22 13:16 Perry Smith
  2022-08-22 14:01 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Perry Smith @ 2022-08-22 13:16 UTC (permalink / raw)
  To: Zsh Users


[-- Attachment #1.1: Type: text/plain, Size: 222 bytes --]

This was unexpected:

 % echo 'a/path with spaces/in/quotes'
a/path/in/quotes
 % echo !:1:h
quote>

I was expecting the equivalent of

 % echo 'a/path/in'

What seems to work is

 % echo !:1:h'

It just seemed odd to me.


[-- Attachment #1.2: Type: text/html, Size: 1562 bytes --]

[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Unexpected results
  2022-08-22 13:16 Unexpected results Perry Smith
@ 2022-08-22 14:01 ` Peter Stephenson
  2022-08-22 20:51   ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2022-08-22 14:01 UTC (permalink / raw)
  To: Zsh Users

> On 22/08/2022 14:16 Perry Smith <pedz@easesoftware.com> wrote:
> This was unexpected:
> 
> % echo 'a/path with spaces/in/quotes'
> a/path/in/quotes
> % echo !:1:h
> quote>
> 
> I was expecting the equivalent of
> 
> % echo 'a/path/in'

The :h modifier on history is pretty brutal, yes.  We store the
full history word internally, but a "history word" is before the
lexical analyser has got to work, i.e. the raw expression with
quotes in it.  What you want is that word after it's been
processed internally.  Unfortunately that's a bit of a mouthful...

echo ${${(Q):-"!:1"}:h}

This takes the whole of that history word inside a parameter
expression (there's no parameter before the ":-" so zsh
uses the value after), strips the quotes, and applies the :h
flag to the result of that.

Someone may have a neater method.

You can get this as a ZLE widget; smart-insert-last-word has all
the bits to extract the word itself --- though it's way over the
top for the current purpose --- then all that's needed is the
substitution above just before inserting it on the line --- except
you'd want to re-quote it perhaps with a ${(q-)...} wrapper in
that case.

(Of course I understand the response is most likely to be "umph,
forget it"...)

pws


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Unexpected results
  2022-08-22 14:01 ` Peter Stephenson
@ 2022-08-22 20:51   ` Bart Schaefer
  2022-08-22 20:56     ` Roman Perepelitsa
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2022-08-22 20:51 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh Users

On Mon, Aug 22, 2022 at 7:01 AM Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
>
> The :h modifier on history is pretty brutal, yes.  We store the
> full history word internally, but a "history word" is before the
> lexical analyser has got to work, i.e. the raw expression with
> quotes in it.  What you want is that word after it's been
> processed internally.

echo !:1:Q:h:q

perhaps?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Unexpected results
  2022-08-22 20:51   ` Bart Schaefer
@ 2022-08-22 20:56     ` Roman Perepelitsa
  2022-08-22 21:07       ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Roman Perepelitsa @ 2022-08-22 20:56 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Peter Stephenson, Zsh Users

On Mon, Aug 22, 2022 at 10:52 PM Bart Schaefer
<schaefer@brasslantern.com> wrote:
>
> On Mon, Aug 22, 2022 at 7:01 AM Peter Stephenson
> <p.w.stephenson@ntlworld.com> wrote:
> >
> > The :h modifier on history is pretty brutal, yes.  We store the
> > full history word internally, but a "history word" is before the
> > lexical analyser has got to work, i.e. the raw expression with
> > quotes in it.  What you want is that word after it's been
> > processed internally.
>
> echo !:1:Q:h:q
>
> perhaps?

It expands to this:

  echo 'a/path' 'with' 'spaces/in'

Instead of this:

  echo 'a/path with spaces/in'

Roman.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Unexpected results
  2022-08-22 20:56     ` Roman Perepelitsa
@ 2022-08-22 21:07       ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2022-08-22 21:07 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Peter Stephenson, Zsh Users

On Mon, Aug 22, 2022 at 1:56 PM Roman Perepelitsa
<roman.perepelitsa@gmail.com> wrote:
>
> On Mon, Aug 22, 2022 at 10:52 PM Bart Schaefer
> <schaefer@brasslantern.com> wrote:
> >
> > echo !:1:Q:h:q
> >
> > perhaps?
>
> It expands to this:
>
>   echo 'a/path' 'with' 'spaces/in'

Ah.  So "!:Q:h" (including the double quotes) then, though that has
problems if there are $var in the previously single-quoted expression.

This is why we have ZLE instead of just bang-history, I suppose.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-08-22 21:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-22 13:16 Unexpected results Perry Smith
2022-08-22 14:01 ` Peter Stephenson
2022-08-22 20:51   ` Bart Schaefer
2022-08-22 20:56     ` Roman Perepelitsa
2022-08-22 21:07       ` Bart Schaefer

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).