Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: (z) word splitting on one word



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