Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: add-path, rm-path
- X-seq: zsh-users 9459
- From: Deliverable Mail <deliverable@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, zsh-users@xxxxxxxxxx
- Subject: Re: add-path, rm-path
- Date: Wed, 28 Sep 2005 20:07:41 -0700
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:references; b=lxDbBYEr1Y3L+j57VcxTrXhKNyzRsRHhUZtdj4z85+fJfG/rrcDlZ0KJI7qtSkQsc7HZHjG2EGCGy16sTRhe7v/u54ZaHykJJK7qAWjY1DQDM19y4K+po5gOgnH+Sgd7WeamOM9rIWdmephtPPPrY5UNHw4o6+mzdtizEOGvNgo=
- In-reply-to: <1050929030313.ZM25022@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <7c737f3005092815162ea22b0c@xxxxxxxxxxxxxx> <1050929030313.ZM25022@xxxxxxxxxxxxxxxxxxxxxxx>
- Reply-to: Deliverable Mail <deliverable@xxxxxxxxx>
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@xxxxxxxxxxxxxxxx> 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author