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

Re: auto-reflesh $PATH



Kazuhiko Uebayashi <kzhk75@xxxxxxxxx>:
> Is it possible to reflesh $PATH "automatically" in Zsh?
> If possible, what should I do?
> 
> In my environment,
>    echo $PATH
>    /home/kazu/local/bin:/usr/local/bin:/usr/bin:/bin
>    echo $path
>    /home/kazu/local/bin /usr/local/bin:/usr/bin:/bin
> 
> In Bash, I put some executable file in $PATH
> then the executable file immediately works.

Actually, new binaries, that are put into your path _will_ work
immediately. But the $PATH is not automatically re-hashed.

That is why the completion code won't find matches. And this is also,
why zsh's autocorrection feature (set correct) will try to present
"corrected" commands, instead of the one you entered.

'hash -r' rehashes the $PATH.

Yet, you are looking for something automatic.
Bart Schaefer presented a solution for this and compsys in
zsh-users #8059¹.

If you also need a solution for the autocorrection issue, it would be
possible to wrap code around the 'accept-line' zle widget, that checks
if the first word on the commandline is in ${(k)commands},
${(k)builtins} etc., and if it's not automatically issue 'hash -r' for
you.

While this won't solve every problem, it would sure catch the most
common ones.

Regards, Frank

¹ <http://www.zsh.org/mla/users/2004/msg01066.html>

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925



Messages sorted by: Reverse Date, Date, Thread, Author