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

Re: PATCH: preexec sometimes gets wrong command

On Tue, 10 Apr 2001, Bart Schaefer wrote:
> I'd actually vote for:
> 	$1	the history line, or empty
> 	$2	getjobtext(), or empty (is it ever?)
> 	$3	getpermtext() (what your patch passes as $2)

Seems like a good idea to me, so I added the extra argument.
(FYI: getjobtext() will never be empty.)

Does anyone have any concerns about my committing this?

Index: Doc/Zsh/func.yo
@@ -172,8 +172,14 @@
 Executed just after a command has been read and is about to be
-executed.  If the history mechanism is active, the string to be
-executed is passed as an argument.
+executed.  If the history mechanism is active (and the line was not
+discarded from the history buffer), the string that the user typed is
+passed as the first argument, otherwise it is an empty string.  The
+actual command that will be executed (including expanded aliases) is
+passed in two differnt forms: the second argument is a single-line,
+size-limited version of the command (with things like function bodies
+elided); the third argument contains the full text what what is being
 cindex(signals, trapping)
Index: Src/init.c
@@ -135,15 +135,23 @@
 	    if (toplevel && (preprog = getshfunc("preexec")) != &dummy_eprog) {
 		LinkList args;
 		int osc = sfcontext;
+		char *cmdstr;
 		args = znewlinklist();
 		zaddlinknode(args, "preexec");
-		if (hist_ring)
+		/* If curline got dumped from the history, we don't know
+		 * what the user typed. */
+		if (hist_ring && curline.histnum == curhist)
 		    zaddlinknode(args, hist_ring->text);
+		else
+		    zaddlinknode(args, "");
+		zaddlinknode(args, getjobtext(prog, NULL));
+		zaddlinknode(args, cmdstr = getpermtext(prog, NULL));
 		sfcontext = SFC_HOOK;
 		doshfunc("preexec", preprog, args, 0, 1);
 		sfcontext = osc;
+		zsfree(cmdstr);
 		freelinklist(args, (FreeFunc) NULL);
 		errflag = 0;

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