Oh My Zsh Plugin System and External Command Environment Variable Propagation
0 reputation · 12 Apr 2020, 13:11 UTC
0 reputation · 12 Apr 2020, 13:11 UTC
Determine whether environment variables defined in Oh My Zsh plugins are reliably propagated to external commands invoked from the shell prompt, taking into account the plugin load order and the export semantics required for visibility to child processes.
Plugins are sourced sequentially from the $plugins array; later plugins can overwrite or unset variables set by earlier ones, and only variables prefixed with export (or set under setopt ALLEXPORT) are exported to the environment of subsequently executed external commands. Because Oh My Zsh provides no automatic dependency management or namespace isolation for plugin‑defined variables, the final value visible to an external command depends on the order of plugins and whether any later source overrides or unsets the variable.
export prefix remain accessible to external commands invoked after the plugin is sourced?$plugins list?34775 reputation · 12 Apr 2020, 22:40 UTC
export remain shell‑only; they are not passed to external commands unless setopt ALLEXPORT is active..zshrc after the plugin block) or use typeset -gx/export in a file sourced after the plugin list, or rely on a plugin that ensures no later source modifies it.$plugins array before the interactive prompt appears.export (or made global via setopt ALLEXPORT) are placed in the shell’s environment and inherited by child processes.~/.oh-my-zsh/custom/plugins/testenv/testenv.plugin.zsh containing:# exported variable
export TEST_PLUGIN_VAR="first"
# non‑exported variable
TEST_LOCAL_VAR="local"
testenv to the plugins array in .zshrc and start a new shell.echo $TEST_PLUGIN_VAR $TEST_LOCAL_VAR – both appear.printenv TEST_PLUGIN_VAR – shows the value; printenv TEST_LOCAL_VAR shows nothing.env | grep TEST_PLUGIN_VAR – you see the variable; env | grep TEST_LOCAL_VAR – no output.# second plugin
unset TEST_PLUGIN_VAR
testenv in the plugins list, restart the shell, and repeat the env check – the variable will be absent.Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 12 Apr 2020, 15:04 UTC
Zsh itself provides a mechanism the answer didn't mention: typeset -r (or readonly) makes a variable immutable for the rest of the shell session. If a plugin does export readonly MY_VAR=value (or typeset -gxr MY_VAR=value), any later plugin that tries to unset or reassign MY_VAR will emit a "readonly variable" error but Zsh continues sourcing; the original value stays exported and visible to child processes. This is the closest thing to a guarantee Oh My Zsh's plugin system can offer, though it prevents legitimate updates from the defining plugin too. Use only for truly constant configuration.