zsh-users
 help / color / mirror / code / Atom feed
* add-path, rm-path
@ 2005-09-28 22:16 Deliverable Mail
  2005-09-29  3:03 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Deliverable Mail @ 2005-09-28 22:16 UTC (permalink / raw)
  To: zsh-users

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

Many people have python-esque scripts which add a path to a PATH-like
variable only if it's not there already, or remove it from there completely.
I wonder whether zsh has it embedded?
 Cheers,
Alexy

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

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

* Re: add-path, rm-path
  2005-09-28 22:16 add-path, rm-path Deliverable Mail
@ 2005-09-29  3:03 ` Bart Schaefer
  2005-09-29  3:07   ` Deliverable Mail
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2005-09-29  3:03 UTC (permalink / raw)
  To: zsh-users

On Sep 28,  3:16pm, Deliverable Mail wrote:
} 
} Many people have python-esque scripts which add a path to a PATH-like
} variable only if it's not there already, or remove it from there completely.
} I wonder whether zsh has it embedded?

Zsh has three components that together accomplish this.  The first is
automatic linkage between arrays and colon-separated scalars, in this
case the array "path" and the scalar "PATH".

The second is "typeset -U" for creating self-uniquifying arrays.

The third is ${array:#pattern} for removing elements matching a pattern
from an array.

The only time you need a function is when you want to control the order
in which the single remaining instance of a duplicated element appears
in the array, after de-duping.  The "typeset -U" behavior is to keep
the one with the lowest array index, even if that means inserting a new
element and deleting an existing equivalent one.


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

* Re: add-path, rm-path
  2005-09-29  3:03 ` Bart Schaefer
@ 2005-09-29  3:07   ` Deliverable Mail
  0 siblings, 0 replies; 3+ messages in thread
From: Deliverable Mail @ 2005-09-29  3:07 UTC (permalink / raw)
  To: Bart Schaefer, zsh-users

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

I must say I'm impressed even more with zsh. So far it has absolutely
everything imaginable! Thanks for all the fish. :)
 Cheers,
Alexy
 On 9/28/05, Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> On Sep 28, 3:16pm, Deliverable Mail wrote:
> }
> } Many people have python-esque scripts which add a path to a PATH-like
> } variable only if it's not there already, or remove it from there
> completely.
> } I wonder whether zsh has it embedded?
>
> Zsh has three components that together accomplish this. The first is
> automatic linkage between arrays and colon-separated scalars, in this
> case the array "path" and the scalar "PATH".
>
> The second is "typeset -U" for creating self-uniquifying arrays.
>
> The third is ${array:#pattern} for removing elements matching a pattern
> from an array.
>
> The only time you need a function is when you want to control the order
> in which the single remaining instance of a duplicated element appears
> in the array, after de-duping. The "typeset -U" behavior is to keep
> the one with the lowest array index, even if that means inserting a new
> element and deleting an existing equivalent one.
>

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

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

end of thread, other threads:[~2005-09-29  3:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-28 22:16 add-path, rm-path Deliverable Mail
2005-09-29  3:03 ` Bart Schaefer
2005-09-29  3:07   ` Deliverable Mail

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