2

Is there a way to get the full path of the current zsh startup file being processed (e.g. zshrc or zshenv)? In other words, imagine I have a zshrc file that can either be located at /usr/local/etc/zshrc or $HOME/.zshrc. Inside this zshrc file, I need to do different things depending on its location. The usual $0 doesn't work, because it contains the path to the zsh binary instead of the zshrc script.

3

With prompt expansion, %N gives you that (the current script/sourced-file/function).

So you can do:

print -P %N

or get it from ${(%):-%N}.

See also the $funcsourcetrace for the files of the call stack.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.