* How to clean up path most efficiently?
@ 2004-06-17 16:11 Jarkko Maja
2004-06-17 16:34 ` Peter Stephenson
2004-06-17 16:50 ` Paul Lew
0 siblings, 2 replies; 9+ messages in thread
From: Jarkko Maja @ 2004-06-17 16:11 UTC (permalink / raw)
To: zsh-users
Hi,
I have tons of directories in my $PATH, but only a
handful of them are needed in each my machine; other
directories simply do not exist. How could I clean up
the non-existing dirs from my $PATH most efficiently?
Doing a for loop in ~/.zshrc just for that sounds a
bit overkill, but at least I couldn't spot anything
like this on man page.
Thanks.
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to clean up path most efficiently?
2004-06-17 16:11 How to clean up path most efficiently? Jarkko Maja
@ 2004-06-17 16:34 ` Peter Stephenson
2004-06-17 17:21 ` Paul Lew
2004-06-22 19:46 ` Timothy Luoma
2004-06-17 16:50 ` Paul Lew
1 sibling, 2 replies; 9+ messages in thread
From: Peter Stephenson @ 2004-06-17 16:34 UTC (permalink / raw)
To: zsh-users
Jarkko Maja wrote:
> I have tons of directories in my $PATH, but only a
> handful of them are needed in each my machine; other
> directories simply do not exist. How could I clean up
> the non-existing dirs from my $PATH most efficiently?
> Doing a for loop in ~/.zshrc just for that sounds a
> bit overkill, but at least I couldn't spot anything
> like this on man page.
It should be as simple as:
path=($^path(N))
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
www.mimesweeper.com
**********************************************************************
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to clean up path most efficiently?
2004-06-17 16:34 ` Peter Stephenson
@ 2004-06-17 17:21 ` Paul Lew
2004-06-22 19:46 ` Timothy Luoma
1 sibling, 0 replies; 9+ messages in thread
From: Paul Lew @ 2004-06-17 17:21 UTC (permalink / raw)
To: Peter Stephenson; +Cc: zsh-users
>>>>> "Peter" == Peter Stephenson <pws@csr.com> writes:
>> I have tons of directories in my $PATH, but only a handful of
>> them are needed in each my machine; other directories simply do
>> not exist. How could I clean up the non-existing dirs from my
>> $PATH most efficiently? Doing a for loop in ~/.zshrc just for
>> that sounds a bit overkill, but at least I couldn't spot
>> anything like this on man page.
Peter> It should be as simple as:
Peter> path=($^path(N))
This is cool. Few questions for efficiency here:
(1) which one is more efficient? The parameter expansion with
NULL_GLOB or read in the ready list from disk? Originally I setup
the path with a loop that will check for [[ -d $dir ]] but the
speed is greatly improved with the cached file. Since most
of the dir in our path are auto mounted, caching seems the
better way.
(2) when is zsh rehash the path? vared path? path=(...) ? If
path is rehased everytime path is updated, then will it be
bad practice to do:
PATH=a:b:c
PATH=$PATH:d:e
PATH=$PATH:f:g
This is to make the script fit on terminal width but will it
be costly?
TIA.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to clean up path most efficiently?
2004-06-17 16:34 ` Peter Stephenson
2004-06-17 17:21 ` Paul Lew
@ 2004-06-22 19:46 ` Timothy Luoma
2004-06-23 2:23 ` Sami Samhuri
` (2 more replies)
1 sibling, 3 replies; 9+ messages in thread
From: Timothy Luoma @ 2004-06-22 19:46 UTC (permalink / raw)
To: zsh-users
On 6/17/04 12:34 PM, "Peter Stephenson" <pws@csr.com> wrote:
> Jarkko Maja wrote:
>> I have tons of directories in my $PATH, but only a
>> handful of them are needed in each my machine; other
>> directories simply do not exist. How could I clean up
>> the non-existing dirs from my $PATH most efficiently?
>> Doing a for loop in ~/.zshrc just for that sounds a
>> bit overkill, but at least I couldn't spot anything
>> like this on man page.
yeah I did something like this a long time ago, but since it rarely changes
per-machine, it was overkill
PATH=""
for dir in /usr/bin /bin /sbin /usr/local/sbin /usr/local/bin $HOME/bin
do
if [[ -d $dir ]]
then
PATH=$dir:$PATH
fi
done
(Note: that list of dirs is in reverse order of preference due to the way
the loop is put together, to avoid ':' as the first character in the PATH
string.
> It should be as simple as:
>
> path=($^path(N))
Does that go through the current $PATH and delete all the folders that
aren't listed in there?
Is it supposed to be lowercase?
TjL
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to clean up path most efficiently?
2004-06-22 19:46 ` Timothy Luoma
@ 2004-06-23 2:23 ` Sami Samhuri
2004-06-23 7:09 ` Bart Schaefer
2004-06-23 8:56 ` Peter Stephenson
2 siblings, 0 replies; 9+ messages in thread
From: Sami Samhuri @ 2004-06-23 2:23 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 501 bytes --]
* It was Tue, Jun 22, 2004 at 03:46:33PM -0400 when Timothy Luoma said:
> On 6/17/04 12:34 PM, "Peter Stephenson" <pws@csr.com> wrote:
[...]
> > It should be as simple as:
> >
> > path=($^path(N))
>
> Does that go through the current $PATH and delete all the folders that
> aren't listed in there?
>
> Is it supposed to be lowercase?
zsh uses $PATH, and also $path. $path differs in that it is a zsh array.
At least, this is my understanding of how things work.
--
Sami Samhuri
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to clean up path most efficiently?
2004-06-22 19:46 ` Timothy Luoma
2004-06-23 2:23 ` Sami Samhuri
@ 2004-06-23 7:09 ` Bart Schaefer
2004-06-23 8:56 ` Peter Stephenson
2 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2004-06-23 7:09 UTC (permalink / raw)
To: zsh-users
On Tue, 22 Jun 2004, Timothy Luoma wrote:
> > path=($^path(N))
>
> Does that go through the current $PATH and delete all the folders that
> aren't listed in there?
Yes.
> Is it supposed to be lowercase?
Yes, Sami Samhuri has the right of it: $path and $PATH are "tied"
variables, one an array and one a colon-delimited string, both of which
represent the same value. Assign to either one and zsh changes the other
to match.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to clean up path most efficiently?
2004-06-22 19:46 ` Timothy Luoma
2004-06-23 2:23 ` Sami Samhuri
2004-06-23 7:09 ` Bart Schaefer
@ 2004-06-23 8:56 ` Peter Stephenson
2004-06-23 16:55 ` Sami Samhuri
2 siblings, 1 reply; 9+ messages in thread
From: Peter Stephenson @ 2004-06-23 8:56 UTC (permalink / raw)
To: zsh-users
Timothy Luoma wrote:
> > It should be as simple as:
> >
> > path=($^path(N))
>
> Does that go through the current $PATH and delete all the folders that
> aren't listed in there?
I should probably have explained in more detail at the time.
The ^ indicates that anything outside the array should be expanded with
each element, so the expression becomes something like:
path=(/usr/local/bin(N) //usr/nonexistent/bin(N) /usr/bin(N) /bin(N))
The presence of the glob qualifier (N) turns on globbing even though
there are no patterns present (historically, it didn't always do that).
The shell then goes through it turning any name which doesn't exist in the
filesystem into a null string, and passing the rest through, so it
becomes something like:
path=(/usr/local/bin /usr/bin bin)
which then gets assigned back to path. This automatically appears in
PATH as
PATH=/usr/local/bin:/usr/bin:/bin
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
www.mimesweeper.com
**********************************************************************
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to clean up path most efficiently?
2004-06-23 8:56 ` Peter Stephenson
@ 2004-06-23 16:55 ` Sami Samhuri
0 siblings, 0 replies; 9+ messages in thread
From: Sami Samhuri @ 2004-06-23 16:55 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 1184 bytes --]
* It was Wed, Jun 23, 2004 at 09:56:38AM +0100 when Peter Stephenson said:
> Timothy Luoma wrote:
> > > It should be as simple as:
> > >
> > > path=($^path(N))
> >
> > Does that go through the current $PATH and delete all the folders that
> > aren't listed in there?
>
> I should probably have explained in more detail at the time.
>
> The ^ indicates that anything outside the array should be expanded with
> each element, so the expression becomes something like:
>
> path=(/usr/local/bin(N) //usr/nonexistent/bin(N) /usr/bin(N) /bin(N))
>
> The presence of the glob qualifier (N) turns on globbing even though
> there are no patterns present (historically, it didn't always do that).
> The shell then goes through it turning any name which doesn't exist in the
> filesystem into a null string, and passing the rest through, so it
> becomes something like:
>
> path=(/usr/local/bin /usr/bin bin)
>
> which then gets assigned back to path. This automatically appears in
> PATH as
>
> PATH=/usr/local/bin:/usr/bin:/bin
This is great. Thanks for the explanation! For zsh newbies some of the
syntax seems cryptic at first.
--
Sami Samhuri
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: How to clean up path most efficiently?
2004-06-17 16:11 How to clean up path most efficiently? Jarkko Maja
2004-06-17 16:34 ` Peter Stephenson
@ 2004-06-17 16:50 ` Paul Lew
1 sibling, 0 replies; 9+ messages in thread
From: Paul Lew @ 2004-06-17 16:50 UTC (permalink / raw)
To: Jarkko Maja; +Cc: zsh-users
>>>>> "Jarkko" == Jarkko Maja <jarkko1982@yahoo.com> writes:
Jarkko> Hi, I have tons of directories in my $PATH, but only a
Jarkko> handful of them are needed in each my machine; other
Jarkko> directories simply do not exist. How could I clean up the
Jarkko> non-existing dirs from my $PATH most efficiently? Doing a
Jarkko> for loop in ~/.zshrc just for that sounds a bit overkill,
Jarkko> but at least I couldn't spot anything like this on man
Jarkko> page.
This is what I do:
* put all paths together in one list
* walk thru the list and check the existence of each directory and
create a path consists of only the working one
* save this in a host specific file, e.g., zpath.$(hostname)
* upon zsh startup, if .zshenv is newer than this cached file, then
run thru the loop creating the list again. If the cache is newer,
just source it to setup the path.
This works pretty good except if I update the .zshrc first, then login
to update the cache, later I create the missing directory. In this
case, the cache is newer than the .zshenv so it will be used without
recognizing that the directory is updated. I will have to manually
removed the cache file and exec zsh again. Of course, this is because
I dont want the burden of access the filesystem with every login.
Dont know if anyone has better method.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2004-06-23 16:54 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-17 16:11 How to clean up path most efficiently? Jarkko Maja
2004-06-17 16:34 ` Peter Stephenson
2004-06-17 17:21 ` Paul Lew
2004-06-22 19:46 ` Timothy Luoma
2004-06-23 2:23 ` Sami Samhuri
2004-06-23 7:09 ` Bart Schaefer
2004-06-23 8:56 ` Peter Stephenson
2004-06-23 16:55 ` Sami Samhuri
2004-06-17 16:50 ` Paul Lew
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).