Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Something like noglob to inhibit brace expansion?
- X-seq: zsh-users 6655
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Something like noglob to inhibit brace expansion?
- Date: Mon, 6 Oct 2003 19:05:18 +0000
- In-reply-to: <m3n0ce707n.fsf@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <m3wubkmv0y.fsf@xxxxxxxxxx> 	<1031005162121.ZM2735@xxxxxxxxxxxxxxxxxxxxxxx> 	<m3y8vy8nfr.fsf@xxxxxxxxxx> 	<1031006170134.ZM4707@xxxxxxxxxxxxxxxxxxxxxxx> 	<m3n0ce707n.fsf@xxxxxxxxxx>
On Oct 6,  1:19pm, Lloyd Zusman wrote:
}
} Hmm ... isn't one of the three arguments passed to preexec already the
} raw, unexpanded command?  If so, is there a way to use preexec to modify
} the command line that is about to be executed?
There is not.  We considered that, but my experience with a similar hook
in the zmail scripting language led me to recommend against it.  It's
much too easy to get yourself into a state where the shell doesn't work
at all because a typo in preexec breaks or disables everything.
However, you could do this:
    preexec() {
    	setopt localoptions noksharrays
	typeset -gH _DONE_=0
	local -a cmd
	cmd=( ${(z)1} )
	if [[ $cmd[1] == raw ]]
	then
	    if [[ $cmd[2] == '{' && $cmd[-1] == '}' ]]
	    then
		_DONE_=1
		eval $cmd[3] "${(@q)cmd[4,-2]}"
	    elif [[ -z ${(M)cmd#([;|&]|&&|\{|\|\|)} ]]
	    then
		_DONE_=1
		eval $cmd[2] "${(@q)cmd[3,-1]}"
	    else
		print -u2 raw: syntax error: all bets are off
	    fi
	fi
    }
    alias raw='((_DONE_)) ||'
This allows you to write stuff like
    raw echo this must be a simple $(command) but is *not* expanded
    raw { echo this must parse OK but is $(not expanded); echo see? }
But note that
    echo raw has no effect ; raw echo in the middle like this
Messages sorted by:
Reverse Date,
Date,
Thread,
Author