Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

RE: Scope of local parameters



> 
> Are there ways to limit the scope of local parameters besides
> functions?  Say you want to colorize the prompt, and you use
> helper variables for the color escape sequences:
> 
>   local RED=...
>   local GREEN=...
>   local BLUE=...
> 
>   PS1=<use RGB variables here>
> 
> If I do this in ~/.zshrc, or a file sourced by .zshrc, the
> variables declared local do not disappear after sourcing ~/.zshrc.
> 
> One way to work around this is to wrap the PS1 initialization in
> an auxiliary function, but then you have the same problem with
> the scope of the function. :-)  Alternatively, one could
> 
>   unset RED GREEN BLUE
> 
> after setting PS1, but this doesn't feel quite right.  What if
> the parameters RED GREEN BLUE already existed?  There has to be
> a better way.
> 

Would you please next time specify Zsh version?


local foo=XXX
"~/.zshrc" 127L, 1859C written

bor@itsrm2% zsh
bor@itsrm2% echo $foo

bor@itsrm2% echo $ZSH_VERSION
4.1.1-test-1

-andrey



Messages sorted by: Reverse Date, Date, Thread, Author