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

Re: Something like noglob to inhibit brace expansion?



On Oct 6, 10:12am, Lloyd Zusman wrote:
}
} Hmm ... or what about this as an even uglier alternative (one long
} line in real life)?
} 
}   alias pr='eval "preexec() { setopt braceexpand; preexec(){} }" && 
}             setopt ignorebraces && noglob print'

No, this won't work -- preexec is executed once before each interactive
command _line_ is executed, not before every individual command in any
pipeline or list.  So in that example, preexec won't be defined until
after it would have executed.  It'll execute before the _next_ command,
but by that time it's too late -- parsing of that next command is over,
and won't have used braceexpand.

You could do it with precmd instead of preexec.

} There's even probably some sort of way to make a generic alias or
} function for this, which can then be applied to any command

You could always do something like this -- modeled on "ttyctl":

    function optctl {
	case $1 in
	-f) if [[ -o localoptions ]]
	    then
		print -u2 optctl: cannot freeze with LOCAL_OPTIONS set
		return 1
	    fi
	    zmodload -i zsh/parameter || return 1
	    typeset -agH _optctl_opts
	    _optctl_opts=( ${(kv)options[@]} )
	    ;;
	-u) unset _optctl_opts
	    ;;
	'') print options are ${${_optctl_opts:+frozen}:-not frozen}
	    ;;
	 *) print -u2 optctl: too many arguments
	    return 1
	    ;;
	esac
    }
    precmd() {
	[[ -n ${_optctl_opts:-} ]] && options=( ${_optctl_opts[@]} )
	# ... whatever you usually have in precmd ...
    }

With the caveat, of course, that precmd itself can't use LOCAL_OPTIONS
if you want this to work.  (The extra :- there is so that NO_UNSET does
not cause zsh to complain.)

} Feature suggestion: how about adding [...] an 'ignore' precommand
} modifier which takes options that can be grouped together, such as -b
} for braces, -g for glob, -v for variable expansion, etc.?

That's an interesting idea, though it may be very difficult to manage
it for those expansions that don't already have options.  Expansions
introduced with '$' in particular are tied to parsing at several levels,
because the presence of '${' or '$(' changes the parse of everything
that follows, up to the matching '}' or ')'.

E.g., if command substitution is turned off but globbing isn't, '$(...)'
ought to become interpretable as a glob with qualifiers; but by the
time zsh gets around to discovering that the 'noglob' et al. builtins
are on the command line, it's already been parsed as a command list.
It's easy to turn a glob pattern back into a plain string, but quite
difficult to turn a command list into a glob pattern.

That's also why ignorebraces is an option rather than a precommand; the
parser has to be changed much earlier.  We'd have to implement "ignore"
as a reserved word like "nocorrect", in which case it can't take options.



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