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

Re: delay argument interpretation



On Jul 21, 12:05pm, Paul Lew wrote:
} Subject: delay argument interpretation
}
} This all work out nice, however, the comment blocks in these files are
} different and I would like to apply a filter (rmcmt in the example
} below) to it so I will only see the source differences:
} 
} 	for i in *.c; do
} 		ask diff =(rmcmt old/$i) =(rmcmt $i)
} 		done

The obvious solution to this specific problem is to use "diff -I <re>" to
ignore lines matching the regular expression <re>.

The other solution that occurs to me is

	function diffsrc() {
	    local x=$[$#-2]
	    diff $*[1,$x] =(rmcmt $*[$x+1]) =(rmcmt $*[$x+2])
	}

	for i in *.c; do ask diffsrc old/$i $i; done

} What can I do to quote the arguments so it will not expand until
} later in function ask?

Something like what Zefram suggested is the only way; really do quote them
yourself.  In csh I'd use an alias with \!: expansions like this:

	alias ask 'echo -n \!*:q"? [y/n] "; askify \!*'

(and then "askify" would be a script that does everything but the echo in
your "ask").  But zsh doesn't have such a mechanism for re-quoting the
command line at alias time, before any of it gets expanded.  The closest
you can get is somthing like

	alias ask='noglob ask'

which delays filename expansion but not command name substitution et. al.
I have this little function:

    show () {
        show=() 
        show=($~*) 
        print -rc $show
    }
    alias show='noglob show'

which allows me to do things like

	show **/*.{orig,rej}
    (examine what I see for a bit, then do something else like)
	rm $show
    (which avoids doing the recursive glob twice).

My only complaint about this is that completion for "noglob" gets invoked
if I happen to press TAB, rather than completion for "show".  I think
that's a bug.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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