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

Re: Avoiding the zshells intelligence...in one case



Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> You could try this, but it's potentially risky:
>
> re_nomatch() { { ${~@} } always { setopt nomatch } }
> alias t='setopt nonomatch && noglob re_nomatch echo'

Why is this risky? Because it can leave nomatch in the wrong state?
The following does not have this problem and also takes the other
settings you mentioned into account:

unsetopt_nomatch() {
	if unsetopt | grep -q nonomatch
	then	restore_nomatch() setopt nomatch
	else	restore_nomatch() :
	fi
	unsetopt nomatch
}
noexpand_restore_nomatch() { {
() {
	setopt local_options no_nullglob n_ocshnullglob
	${~@}
} $@ } always {
	restore_nonomatch
	unfunction restore_nomatch
} }
alias noexpand='unsetopt_nomatch; noglob noexpand_restore_nomatch '

Example usage: alias wget='noexpand wget'

It is clumsy, because the "setopt nomatch" must possibly be excluded from
the "localoptions" range; except for using an anonymous function
and passing the arguments to it, I did not find another solution...
To get correct completion for the above alias, I guess you also have to

compdef noexpand_restore_nomatch=noglob

after the initialization of the completion system.



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