From: Peter Stephenson <pws@ifh.de>
To: gkoopman@wi.leidenuniv.nl, zsh-users@math.gatech.edu
Subject: Re: newbie questions
Date: Thu, 09 Oct 1997 16:07:54 +0200 [thread overview]
Message-ID: <199710091407.QAA15018@hydra.ifh.de> (raw)
In-Reply-To: "Guido Koopman"'s message of "Thu, 09 Oct 1997 13:32:02 MET." <199710091132.HAA20755@artemis.wi.leidenuniv.nl>
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 <pws@ifh.de> 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.
next prev parent reply other threads:[~1997-10-09 14:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-10-09 11:32 Guido Koopman
1997-10-09 14:07 ` Peter Stephenson [this message]
1997-10-09 20:41 ` Brandon C. George
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199710091407.QAA15018@hydra.ifh.de \
--to=pws@ifh.de \
--cc=gkoopman@wi.leidenuniv.nl \
--cc=zsh-users@math.gatech.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).