Global variables should be declared with typeset -g option. Partially for documentation purposes, but also because WARN_CREATE_GLOBAL zsh option doesn't like it any other way:
k:138: scalar parameter K_COLOR_DI created globally in function k
k:139: scalar parameter K_COLOR_LN created globally in function k
k:140: scalar parameter K_COLOR_SO created globally in function k
k:141: scalar parameter K_COLOR_PI created globally in function k
k:142: scalar parameter K_COLOR_EX created globally in function k
k:143: scalar parameter K_COLOR_BD created globally in function k
k:144: scalar parameter K_COLOR_CD created globally in function k
k:145: scalar parameter K_COLOR_SU created globally in function k
k:146: scalar parameter K_COLOR_SG created globally in function k
k:147: scalar parameter K_COLOR_TW created globally in function k
k:148: scalar parameter K_COLOR_OW created globally in function k
k:149: scalar parameter K_COLOR_BR created globally in function k
Alternatives
How about switching to an associative array (a.k.a. dictionary/hash-table) instead of a bunch of independent variables? I have successfully done this in oh-my-zsh plugin once: https://github.com/ohmyzsh/ohmyzsh/pull/9437
Summary
Global variables should be declared with
typeset -g
option. Partially for documentation purposes, but also becauseWARN_CREATE_GLOBAL
zsh option doesn't like it any other way:Alternatives
How about switching to an associative array (a.k.a. dictionary/hash-table) instead of a bunch of independent variables? I have successfully done this in oh-my-zsh plugin once: https://github.com/ohmyzsh/ohmyzsh/pull/9437