Just enable extended_glob
. I can't think of a reason not to do it.
The only reason extended_glob
is off by default is because the default configuration is backward-compatible, and this goes back to before extended_glob
existed. It doesn't change the behavior of many things that you're likely to write. The only thing I encounter in practice is that occasionally I need to quote a ^
or #
in a command argument, but that's less common than me wanting to use ^
or #
as a wildcard.
If you want to avoid changing the options in code, make the options local. You need to do that anyway in functions that may run in an unspecified context. Call emulate -L
to set scripting-related options to their default value during the execution of the function, and restore them when the function returns.
function my_function {
emulate -L zsh
setopt extended_glob
…
}
If you want to change the setting just for one line of code, you can put it in an anonymous function.
() { setopt local_options extended_glob; ls ^a }
By the way, currently the *
parameter expansion flag doesn't help because it only affects substitutions, not filename generation (but affecting filename generation would be a useful feature). You can expand a glob inside a parameter substitution with the ${name:-word}
form, which allows name to be omitted, combined with the ${~spec}
form, e.g. echo ${~:-[^a]*}
to list files whose name doesn't start with a
. But echo ${(*)~:-^a*}
doesn't work unless extended_glob
is already enabled, because *
(currently) has no effect on the globbing induced by glob_subst
.