I have a build script that can change what binaries are in my $PATH (it doesn't edit $PATH itself, but it adds/deletes files to folders that are already in $PATH). zsh's autocompletion doesn't update to reflect the files that have been added/deleted in response to the build, so I have to either restart the shell or execute the 'rehash' shell built-in to tell it to update its autocomplete cache.
I decided I wanted to automate running rehash so at first I did this:
build() {
~/bin/real_build && rehash
}
But shell functions run in their own subshell, so rehash would update the cache for the subshell, instead of the shell in the terminal I was using. So I switched to this:
alias build='~/bin/real_build && rehash'
Which works, except when I want to pass arguments to build. If I pass 'clean' I'd like it to execute:
~/bin/real_build clean && rehash
But instead it will do:
~/bin/real_build && rehash clean
So I'm stuck -- I can use an alias and not be able to pass arguments, or I can use a function and not have it actually update the autocomplete entries. Is there a way to make both work?
zsh
before today, but callingrehash
from a function does seem to work for me.