Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: auto-reflesh $PATH
- X-seq: zsh-users 11233
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: auto-reflesh $PATH
- Date: Sat, 03 Mar 2007 16:06:42 -0800
- In-reply-to: <c12037010703031514h2730c96te5b721188deda41d@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <c12037010703031514h2730c96te5b721188deda41d@xxxxxxxxxxxxxx>
On Mar 4, 8:14am, Kazuhiko Uebayashi wrote:
}
} In Bash, I put some executable file in $PATH
} then the executable file immediately works.
To get zsh to have the equivalent behavior, you would need:
unsetopt hashcmds hashdirs hashlistall correct correctall
hash -r
This is not the same as refreshing the hash table of commands found in
the path; insteady it's forcing the hash table to be turned off and to
remain turned off, so that (like bash) zsh re-searches it every time a
command is executed.
However, I don't have a problem with new executables added to the path
being "not found" in zsh 4.2+. Which version of zsh are you running?
} Is it possible to reflesh $PATH "automatically" in Zsh?
Only in so far as you can do anything automatically in zsh, such as by
adding it to a precmd or preexec function.
} If possible, what should I do?
When you know a new executable has been installed, run the command:
rehash
If that's too much effort, try something like this (which assumes you
have NOT used the "unsetopt" command above):
function preexec {
local -a modified_path
modified_path=( ${^path}(Nms${SECONDS}) )
SECONDS=0
if (( $#modified_path ))
then hash -r
fi
}
(Note that this may not work in some older versions of zsh without some
tweaking because of differing interpretations of glob qualifiers.)
That won't catch files being renamed within the same directory in $PATH,
but if you have a lot of directories or a lot of commands in the path it
is probably faster than doing a rehash before every command.
--
Messages sorted by:
Reverse Date,
Date,
Thread,
Author