Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: (z) word splitting on one word
- X-seq: zsh-users 28115
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Julian Prein <druckdev@xxxxxxxxxxxxxx>
- Cc: "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Subject: Re: (z) word splitting on one word
- Date: Thu, 22 Sep 2022 17:16:48 +0200
- Archived-at: <https://zsh.org/users/28115>
- In-reply-to: <fi13aLA23DIaMSQDwFOC7p-W1_XNSmw3Xhh_Fkkq-NUZyxeAVYl5HMY1V3w-Ededqf8f9icKw-9pugvbzme5bmIa9_FB8iNXSU7YZlnoagc=@protonmail.com>
- List-id: <zsh-users.zsh.org>
- References: <fi13aLA23DIaMSQDwFOC7p-W1_XNSmw3Xhh_Fkkq-NUZyxeAVYl5HMY1V3w-Ededqf8f9icKw-9pugvbzme5bmIa9_FB8iNXSU7YZlnoagc=@protonmail.com>
On 9/22/22, Julian Prein <druckdev@xxxxxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author