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

Re: add-path, rm-path



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