zsh-users
 help / color / mirror / code / Atom feed
* Is it possible to clear empty :-tied elements?
@ 2022-07-19 19:54 Sebastian Gniazdowski
  2022-07-20  0:18 ` Bart Schaefer
  2022-07-20 19:32 ` Phil Pennock
  0 siblings, 2 replies; 5+ messages in thread
From: Sebastian Gniazdowski @ 2022-07-19 19:54 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 408 bytes --]

Hi,
I'm using typeset -UT to unique a scalar variable:

export -UT CMAKE_PREFIX_PATH="$ZPFX:$CMAKE_PREFIX_PATH" cmake_prefix_path

The problem is that the variable/array will contain empty element if the
variable is empty when export is run.

I wonder if is it possible to somehow clear such empty entry (i.e.: to
remove :: from "a::b") without another line of code?

-- 
Best regards,
Sebastian Gniazdowski

[-- Attachment #2: Type: text/html, Size: 1207 bytes --]

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

* Re: Is it possible to clear empty :-tied elements?
  2022-07-19 19:54 Is it possible to clear empty :-tied elements? Sebastian Gniazdowski
@ 2022-07-20  0:18 ` Bart Schaefer
  2022-07-20  5:40   ` Sebastian Gniazdowski
  2022-07-20 19:32 ` Phil Pennock
  1 sibling, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2022-07-20  0:18 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Zsh Users

On Tue, Jul 19, 2022 at 12:55 PM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> export -UT CMAKE_PREFIX_PATH="$ZPFX:$CMAKE_PREFIX_PATH" cmake_prefix_path
>
> The problem is that the variable/array will contain empty element if the variable is empty when export is run.

Perhaps this is most easily done with

export -UT CMAKE_PREFIX_PATH="${ZPFX:+$ZPFX:}$CMAKE_PREFIX_PATH"
cmake_prefix_path

??


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

* Re: Is it possible to clear empty :-tied elements?
  2022-07-20  0:18 ` Bart Schaefer
@ 2022-07-20  5:40   ` Sebastian Gniazdowski
  2022-07-20 14:58     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Gniazdowski @ 2022-07-20  5:40 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 464 bytes --]

On Wed, 20 Jul 2022 at 02:18, Bart Schaefer <schaefer@brasslantern.com>
wrote:

>
> Perhaps this is most easily done with
>
> export -UT CMAKE_PREFIX_PATH="${ZPFX:+$ZPFX:}$CMAKE_PREFIX_PATH"
> cmake_prefix_path
>

I was hoping for some miracle but yes, that's apparently the best method,
with a drawback– it's the longer variable that has to be wrapped in ${…:+},
making the line quite long/dense…


-- 
Best regards,
Sebastian Gniazdowski

[-- Attachment #2: Type: text/html, Size: 1191 bytes --]

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

* Re: Is it possible to clear empty :-tied elements?
  2022-07-20  5:40   ` Sebastian Gniazdowski
@ 2022-07-20 14:58     ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2022-07-20 14:58 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Zsh Users

On Tue, Jul 19, 2022 at 10:41 PM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> I was hoping for some miracle but yes, that's apparently the best method, with a drawback– it's the longer variable that has to be wrapped in ${…:+}, making the line quite long/dense…

What about something like ${(j.:.)${(s:@:):-$ZPFX@$CMAKE_PREFIX_PATH}} ?


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

* Re: Is it possible to clear empty :-tied elements?
  2022-07-19 19:54 Is it possible to clear empty :-tied elements? Sebastian Gniazdowski
  2022-07-20  0:18 ` Bart Schaefer
@ 2022-07-20 19:32 ` Phil Pennock
  1 sibling, 0 replies; 5+ messages in thread
From: Phil Pennock @ 2022-07-20 19:32 UTC (permalink / raw)
  To: zsh-users

On 2022-07-19 at 21:54 +0200, Sebastian Gniazdowski wrote:
> export -UT CMAKE_PREFIX_PATH="$ZPFX:$CMAKE_PREFIX_PATH" cmake_prefix_path
> 
> The problem is that the variable/array will contain empty element if the
> variable is empty when export is run.
> 
> I wonder if is it possible to somehow clear such empty entry (i.e.: to
> remove :: from "a::b") without another line of code?

Assign it as an array and do _not_ quote the $ZPFX, so that empty values
are not preserved.

  export -UT CMAKE_PREFIX_PATH cmake_prefix_path=($ZPFX "${(s,:,)CMAKE_PREFIX_PATH}")

If you have to be resilient to SH_WORD_SPLIT being enabled, then replace
$ZPFX with ${==ZPFX} instead.

-Phil


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

end of thread, other threads:[~2022-07-20 19:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19 19:54 Is it possible to clear empty :-tied elements? Sebastian Gniazdowski
2022-07-20  0:18 ` Bart Schaefer
2022-07-20  5:40   ` Sebastian Gniazdowski
2022-07-20 14:58     ` Bart Schaefer
2022-07-20 19:32 ` Phil Pennock

Code repositories for project(s) associated with this 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).