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

Re: Something like noglob to inhibit brace expansion?

Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> writes:

> On Oct 4,  7:40pm, Lloyd Zusman wrote:
> }
> }   % pr {a,b,c,*}
> }   a b c *
> } 
> } What I'd like to see is {a,b,c,*}
> } 
> } Does anyone know of any tricks to get this functionality within
> } an alias?
> It's a little ugly, but:
> 	alias pr='setopt noglob ignorebraces && _pr'
> 	_pr() { print $*; setopt glob braceexpand }
> You can get a little fancier if you want to preserve the exit status of
> 'print', but you get the idea.

Aha!  Thank you.

And I think that the following will take care of the exit code:

  alias pr='setopt noglob ignorebraces && _pr'
  _pr() { print $*; local rc=$?; setopt glob braceexpand; return $rc }

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'

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 to generate
an alias for it without command-line expansion.  Next time I have
trouble sleeping at night, I'll work on that one. :)

Feature suggestion: how about adding an 'ignorebraces' precommand
modifier in a future version of zsh?  Or perhaps even something which
would pass in the completely unglobbed, unexpanded, un-everything'ed
command line.  Or even more radically, how about 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.?

 Lloyd Zusman

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