From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1365 invoked from network); 9 Oct 1997 14:50:01 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 9 Oct 1997 14:50:01 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id KAA27133; Thu, 9 Oct 1997 10:07:50 -0400 (EDT) Resent-Date: Thu, 9 Oct 1997 10:07:29 -0400 (EDT) Message-Id: <199710091407.QAA15018@hydra.ifh.de> To: gkoopman@wi.leidenuniv.nl, zsh-users@math.gatech.edu Subject: Re: newbie questions In-reply-to: "Guido Koopman"'s message of "Thu, 09 Oct 1997 13:32:02 MET." <199710091132.HAA20755@artemis.wi.leidenuniv.nl> Date: Thu, 09 Oct 1997 16:07:54 +0200 From: Peter Stephenson Resent-Message-ID: <"XUeyI.0.tc6.LKEFq"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1068 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Guido Koopman wrote: > - Is there a way to have a functionor alias run before every > external command? I'd like the xterm titlebar reflect the > title of the currently running program, instead of just > 'zsh:$PWD'. Part one of the answer is: at the moment, not without great difficulty. Part two of the answer should really go to zsh-workers: Here's a suggestion for 3.1, but the functional part should apply to 3.0 easily enough. "preexec" is a bit like "precmd", but is executed after the line is read and in addition it tries to make the command line being executed available. This comes from the history list, so hiccups are possible (for example, aliases haven't yet been expanded). It wouldn't be too hard to extract the entry as words instead of a single string. Now you do something like preexec() { typeset words words=(${=1}) print "\033]2;${words[1]}\a" } I though of adding some feature that allowed you to skip the main command, but it's a little dangerous because it's impossible to get out of if you make a mistake. For the same reason, errflag is always set to 0 afterwards. Note that it's too late to alter any aspect of how the command is run, beyond redefining a variable, function or external command, since it has already been parsed. Other possible quirks: preexec does get called before an `fc', even if that is subsequently deleted from the history list, but with my recent fix for r's in command substitution it won't get called from the commands that fc invokes (without that patch, it will). You can alter that by changing the `toplevel' test to `(toplevel || justonce)'. !-history is normal. *** Doc/Zsh/func.yo.preexec Mon Jun 2 08:37:08 1997 --- Doc/Zsh/func.yo Thu Oct 9 15:16:43 1997 *************** *** 73,78 **** --- 73,84 ---- item(tt(precmd))( Executed before each prompt. ) + findex(preexec) + item(tt(preexec))( + 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. + ) item(tt(TRAP)var(NAL))( cindex(signals, trapping) cindex(trapping signals) *** Src/init.c.preexec Thu Oct 9 14:52:52 1997 --- Src/init.c Thu Oct 9 15:54:46 1997 *************** *** 69,75 **** --- 69,89 ---- } if (hend()) { int toksav = tok; + List prelist; + if (toplevel && (prelist = getshfunc("preexec")) != &dummy_list) { + Histent he = gethistent(curhist); + LinkList args; + PERMALLOC { + args = newlinklist(); + addlinknode(args, "preexec"); + if (he && he->text) + addlinknode(args, he->text); + } LASTALLOC; + doshfunc(prelist, args, 0, 1); + freelinklist(args, (FreeFunc) NULL); + errflag = 0; + } if (stopmsg) /* unset 'you have stopped jobs' flag */ stopmsg--; execlist(list, 0, 0); -- Peter Stephenson Tel: +49 33762 77366 WWW: http://www.ifh.de/~pws/ Fax: +49 33762 77413 Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen DESY-IfH, Platanenallee 6, 15738 Zeuthen, Germany.