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

Re: auto-reflesh $PATH

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:

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}) )
      if (( $#modified_path ))
      then hash -r

(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