Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: add-path, rm-path
- X-seq: zsh-users 9458
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: add-path, rm-path
- Date: Thu, 29 Sep 2005 03:03:13 +0000
- In-reply-to: <7c737f3005092815162ea22b0c@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <7c737f3005092815162ea22b0c@xxxxxxxxxxxxxx>
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