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

Re: Defining commands to not evaluate certain metacharacters

On Dec 20,  1:39pm, Lloyd Zusman wrote:
} I want to define a set of commands that I can execute from the command
} line under zsh.

This is very nearly a non-starter.  The shell parses shell syntax, not
the syntax of some other language.

You can get part of the way there with the "noglob" precommand modifier,
but that doesn't change the special meanings of parentheses, braces, or

You can get somewhat farther by using ZLE widgets to read the input and
reprocess it before handing it to the shell parser, but that still means
using some additional step to invoke that ZLE widget.  Theoretically you
could rebind accept-line to a wrapper that checks whether the first word
on the line is one of your special commands, but that gets fragile if you
make any attempt to handle multi-line inputs.

    function quoting-accept-line {
        local q='"' words
	words=( $=BUFFER )
	case $words[1] in
	CMD|etc) BUFFER="$words[1] $q${words[2,-1]}$q";;
	zle .accept-line
    zle -N accept-line quoting-accept-line

However what I'd most recommend is that you write a function that runs a
"while read line; do ...; done" loop, which "eval"s anything that looks
like a shell assignment and otherwise invokes your mathematical processor.

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