Suppose you are working on zsh's source code.

At some point in time you might want to try the code you're writing or changing. One way would be to just call the zsh binary ‘Src/zsh’ after compiling the project's code. The problem with that is, that zsh uses a module system to load features on demand, that are not part of the absolute core code of the shell. And it looks for its module libraries somewhere on your system, not however in your zsh source code repository. This is obviously a good thing, because you don't want attackers to be able to just drop a ‘’ file somewhere to get access to your system. ☺

There are two situations, where you can get away with just using ‘Src/zsh’ anyway: You're testing features that work in scripts and don't need to load any modules; or you've got the same zsh version installed on your system, that you're also working on and you don't actually change any of the module code, but just need to load a module to get to your test.

If you need to test code that touches modules, you could install the shell to your system. But that's cumbersome and takes a lot of time. Especially if you need to test lots of different builds, like you do when you use git bisect to chase down a bug.

…and that's what I did today. So I actually wanted to use the binaries I just built from the source. How to do that then? Well, you need to adjust at least ‘$module_path’, which you can't do via a parent process's environment for the security reason I mentioned earlier.

The way I did it was to use ‘$ZDOTDIR’ to provide ‘Src/zsh’ with a testing setup in the ‘.zshenv’ file in that directory, that basically did this:

if ! test -d _modules_; then
    mkdir -p _modules_/zsh || exit 1

cd _modules_/zsh || exit 1
for mod in "${root}"/Src/**/*.so; do
    test -h "${mod:t}" && continue
    ln -s "$mod" "${mod:t}" || exit 1
cd "$root" || exit 1

# Setup the shell's load paths for functions and modules:
fpath=( "${root}/Completion" )
module_path=( "${root}/_modules_" )

If you want to use zsh from its source directory, I've thrown together a small repository that contains the setup I used (well, a slightly more polished version):

Posted Sat 26 Sep 2015 21:56:46 CEST Tags: