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

Re: sound policy on global variables for "distributed" DWIM function

On Jul 23,  1:25am, Emanuel Berg wrote:
} But it doesn't have to be global outside the file
} where those couple of functions are defined.

Shells do not, generally speaking, have file-scoped variables.  You
get globals, variables that are local to functions, and the exported
process environment, and that's about it.

Howver, zsh does have yet another place to stash stuff like this:
The zstyle mechanism.  The ":completion:..." format is nothing but a
convention used in compsys; styles can actually look like anything
you want.

So you could have file names for contexts, e.g.

    zstyle '*/.zsh/dump' file-extension png

and then

    dump-vt () {
	local ext
	zstyle -s $HOME/.zsh/dump file-extension ext
	local file=$1.${ext:-png}
	# ... etc ...

You could also have a different file-extension based on the current
working directory, or whatever.

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