zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Julian Prein <druckdev@protonmail.com>
Cc: "zsh-users@zsh.org" <zsh-users@zsh.org>
Subject: Re: (z) word splitting on one word
Date: Thu, 22 Sep 2022 17:16:48 +0200	[thread overview]
Message-ID: <CAHYJk3QB4mMDWjH_YZVp5BB5C2D-vqmqKVEVe3cCjcvY-YeSCA@mail.gmail.com> (raw)
In-Reply-To: <fi13aLA23DIaMSQDwFOC7p-W1_XNSmw3Xhh_Fkkq-NUZyxeAVYl5HMY1V3w-Ededqf8f9icKw-9pugvbzme5bmIa9_FB8iNXSU7YZlnoagc=@protonmail.com>

On 9/22/22, Julian Prein <druckdev@protonmail.com> wrote:
> Hi!
>
> I am trying to get the last word of LBUFFER.
>
> What I did previously was:
>
>     ${${(z)LBUFFER}[-1]}
>
> This worked flawlessly until I noticed today that it misbehaves if LBUFFER
> contains only one word. In this case it seems like `[-1]` acts on a scalar,
> as
> it expands to the last character instead of LBUFFER as I would expect.
>
> Is this expected behaviour?
>
> I now work around it by prepending LBUFFER with a dummy word so that it
> always
> has at least two words (I know that it is not empty). But this feels very
> hacky.
>
> Do you know of a better way?

${${(Az)LBUFFER}[-1]}

-- 
Mikael Magnusson


  reply	other threads:[~2022-09-22 15:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-22 13:44 Julian Prein
2022-09-22 15:16 ` Mikael Magnusson [this message]
2022-09-24  0:38   ` Julian Prein

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=CAHYJk3QB4mMDWjH_YZVp5BB5C2D-vqmqKVEVe3cCjcvY-YeSCA@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=druckdev@protonmail.com \
    --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).