zsh-users
 help / color / mirror / code / Atom feed
* newbie questions
@ 1997-10-09 11:32 Guido Koopman
  1997-10-09 14:07 ` Peter Stephenson
  1997-10-09 20:41 ` Brandon C. George
  0 siblings, 2 replies; 3+ messages in thread
From: Guido Koopman @ 1997-10-09 11:32 UTC (permalink / raw)
  To: ZSH users mailing list

Hello, zsh fans.
Last week I installed zsh v3.0.5 at home and had lots of fun
composing my ~/.zshrc. It took me a while to figure out how
to convert my tcsh stuff to zsh, but everything works fine now.
I still have a few questions however:
- I aliased which-command='whence -vaf', which gives more info
  than 'whence -c'. But when I type 'ls' and press F4 (bound to
  which-command), I only get 'ls is /bin/ls' instead of 'ls is
  aliased to 'ls --color'' _and_ 'ls is /bin/ls'.

- 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'.

- Is there a way (function/alias/builtin) to convert a given
  path to an absolute path?

Guido Koopman

"I've got to find a hydrant." - Big Dog
"OK. But first,... let's build a submarine!" - Little Dog
(2 Stupid Dogs, "Seeing Eye Dogs"


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: newbie questions
  1997-10-09 11:32 newbie questions Guido Koopman
@ 1997-10-09 14:07 ` Peter Stephenson
  1997-10-09 20:41 ` Brandon C. George
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 1997-10-09 14:07 UTC (permalink / raw)
  To: gkoopman, zsh-users

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: newbie questions
  1997-10-09 11:32 newbie questions Guido Koopman
  1997-10-09 14:07 ` Peter Stephenson
@ 1997-10-09 20:41 ` Brandon C. George
  1 sibling, 0 replies; 3+ messages in thread
From: Brandon C. George @ 1997-10-09 20:41 UTC (permalink / raw)
  To: gkoopman; +Cc: zsh-users

On Thu, Oct 09, 1997 at 01:32:02PM +0200, Guido Koopman wrote:
> Hello, zsh fans.
> 
> - 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'.

I can show you what I have.

> # Function executed by zsh when directory changed to put directory
> # in xterm title.  Also make sure it is set immediately when new
> # xterm started.
> if [ "$TERM" = "xterm" ] || [ "$TERM" = "dtterm" ]; then
>   echo -n "\e]2;$HOSTNAME:$PWD\007"
>   function precmd () {
>     echo -n "\e]2;$HOSTNAME:$PWD\007\e]1;$HOSTNAME\007"
>   }
> fi

Hopefully this was one of the things you were looking for.  This also puts
the command in the window title.  I don't remember
where I found this.  It may be with the distribution.

Brandon

-- 
                |\/\/\/|
                |      |
                | (o)(o)
+==========OOOO==========OOOO==========+
| Brandon George       bcgeorge@ou.edu |
| OU CS Department       Systems Admin |
| PGP key:  http://cs.ou.edu/~bcgeorge |
+======================================+


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-10-09 20:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-09 11:32 newbie questions Guido Koopman
1997-10-09 14:07 ` Peter Stephenson
1997-10-09 20:41 ` Brandon C. George

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).