zsh-workers
 help / color / mirror / code / Atom feed
* Zsh "POSTPROMPT" Feature
@ 1996-05-25 17:20 Greg J. Badros
  1996-05-25 23:01 ` Andrew J Cosgriff
  0 siblings, 1 reply; 3+ messages in thread
From: Greg J. Badros @ 1996-05-25 17:20 UTC (permalink / raw)
  To: hzoli

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2207 bytes --]

Hi,
  First let me thank you for all your work on Zsh... it is an excellent
shell that has proved incredibly useful to my daily work.  Thanks!
  One feature that I've not seen talked about but that would be useful
(mostly in an X environment) is the addition of a POSTPROMPT variable.  I
have patches for zsh-2.5.03 that implement this, and then my .zshrc sets 
my POSTPROMPT to
{%^[]0;%H^G%}
(Where ^[ is ESC, ^G is Ctrl-G-- the xterm sequence for setting the title
and icon). [The %H is a change to print the last/current history item].
  The changes are pretty simple, and add almost nothing to zsh's size, but
prove very helpful in negotiating a large number of xterm-s doing various
things.
  For zsh2.6, my patches are attached but not perfect.  I don't know the
best place to print out the postprompt... I do it in parse.c, now, but may
not have the right guards to prevent printing of the prompt in scripts.
Also, the %H addition to the special prompt sequences might better be
replaced by a general mechanism to give the last commandline (as a special
variable, perhaps).  You certainly could pick a better spot to output the
prompt-- I was just trying different places, from trashzle() to parse, to
lots in between.  Ideally, one would like to postpone it until right
before exec'ing the process (then it might be "EXECPROMPT" or
"PREEXECPROMPT".  Also it's not clear that many of the prompt characters
are useful in this operation, so the feature could change to a postcmdfcn,
like the pre-prompt function.
  Note, for me building under solaris, I added index.c which contains
calls to strchr and strrchr for index and rindex.  These only get linked
in w/ ucb libraries, but the ucb libraries cause an off-by-two characters
bug in the pattern matching section.  I don't know if this is a problem
with the configuration that doesn't detect it shouldn't use index/rindex,
or what, but this is a simple solution.

Patches are attached.  Thanks for your time, both in dealing with my 
note, and in general for Zsh.

Greg J. Badros                 8816 Nesbit Ave N., Apt 303
gjb@cs.duke.edu                Seattle, WA  98103-4067
http://www.cs.duke.edu/~gjb    voice 206/528.7513   fax 206/523.9328


[-- Attachment #2: Type: TEXT/PLAIN, Size: 4209 bytes --]

diff -r -c zsh-2.6-beta19/Makefile myzsh-2.6-beta19a/Makefile
diff -r -c zsh-2.6-beta19/Src/Makefile myzsh-2.6-beta19a/Src/Makefile
*** zsh-2.6-beta19/Src/Makefile	Fri May 24 21:29:14 1996
--- myzsh-2.6-beta19a/Src/Makefile	Fri May 24 16:14:04 1996
***************
*** 103,109 ****
  $Umath.o $Umem.o $Uparams.o $Uparse.o $Usignals.o $Usubst.o $Utext.o \
  $Uutils.o $Uwatch.o $Uzle_bindings.o $Uzle_hist.o $Uzle_main.o \
  $Uzle_misc.o $Uzle_move.o $Uzle_refresh.o $Uzle_tricky.o $Uzle_utils.o \
! $Uzle_vi.o $Uzle_word.o index.c
  
  # auxiliary files
  AUX = Makefile.in .indent.pro signames.awk makepro.sed ansi2knr.c TAGS tags
--- 103,109 ----
  $Umath.o $Umem.o $Uparams.o $Uparse.o $Usignals.o $Usubst.o $Utext.o \
  $Uutils.o $Uwatch.o $Uzle_bindings.o $Uzle_hist.o $Uzle_main.o \
  $Uzle_misc.o $Uzle_move.o $Uzle_refresh.o $Uzle_tricky.o $Uzle_utils.o \
! $Uzle_vi.o $Uzle_word.o $Uindex.c
  
  # auxiliary files
  AUX = Makefile.in .indent.pro signames.awk makepro.sed ansi2knr.c TAGS tags
Only in myzsh-2.6-beta19a/Src: core
diff -r -c zsh-2.6-beta19/Src/globals.h myzsh-2.6-beta19a/Src/globals.h
*** zsh-2.6-beta19/Src/globals.h	Mon May 20 05:39:57 1996
--- myzsh-2.6-beta19a/Src/globals.h	Fri May 24 15:51:09 1996
***************
*** 325,330 ****
--- 325,331 ----
  
  EXTERN char *zoptarg;		/* $OPTARG     */
  EXTERN long zoptind;		/* $OPTIND     */
+ EXTERN char *postprompt;	/* $POSTPROMPT */
  EXTERN char *prompt;		/* $PROMPT     */
  EXTERN char *prompt2;		/* etc.        */
  EXTERN char *prompt3;
diff -r -c zsh-2.6-beta19/Src/hashtable.h myzsh-2.6-beta19a/Src/hashtable.h
*** zsh-2.6-beta19/Src/hashtable.h	Mon May  6 07:08:58 1996
--- myzsh-2.6-beta19a/Src/hashtable.h	Fri May 24 15:53:38 1996
***************
*** 145,150 ****
--- 145,151 ----
  IPDEF7("POSTEDIT", &postedit),
  IPDEF7("READNULLCMD", &readnullcmd),
  IPDEF7("RPROMPT", &rprompt),
+ IPDEF7("POSTPROMPT", &postprompt),
  IPDEF7("PS1", &prompt),
  IPDEF7("PS2", &prompt2),
  IPDEF7("PS3", &prompt3),
diff -r -c zsh-2.6-beta19/Src/init.c myzsh-2.6-beta19a/Src/init.c
*** zsh-2.6-beta19/Src/init.c	Thu May 23 03:28:22 1996
--- myzsh-2.6-beta19a/Src/init.c	Fri May 24 15:52:03 1996
***************
*** 593,598 ****
--- 593,599 ----
  	prompt3 = ztrdup("");
  	prompt4 = ztrdup("");
      }
+     postprompt = ztrdup("");
      sprompt = ztrdup("zsh: correct '%R' to '%r' [nyae]? ");
  
      if (!(ttystrname = ztrdup(ttyname(SHTTY))))
Binary files zsh-2.6-beta19/Src/init.o and myzsh-2.6-beta19a/Src/init.o differ
Binary files zsh-2.6-beta19/Src/params.o and myzsh-2.6-beta19a/Src/params.o differ
diff -r -c zsh-2.6-beta19/Src/parse.c myzsh-2.6-beta19a/Src/parse.c
*** zsh-2.6-beta19/Src/parse.c	Fri May 17 07:25:21 1996
--- myzsh-2.6-beta19a/Src/parse.c	Fri May 24 21:33:59 1996
***************
*** 119,124 ****
--- 119,132 ----
      } else {
  	l->right = par_event();
      }
+     /* gjb added */
+     if (interact && postprompt != 0 && *postprompt != NULL) {
+         int plen = 0;
+ 	curhist++;
+ 	/*	printf("%s", putprompt(postprompt,&plen,NULL,0)); */
+ 	fflush(stdout);
+ 	curhist--;
+     }
      return l;
  }
  
Binary files zsh-2.6-beta19/Src/parse.o and myzsh-2.6-beta19a/Src/parse.o differ
diff -r -c zsh-2.6-beta19/Src/version.h myzsh-2.6-beta19a/Src/version.h
*** zsh-2.6-beta19/Src/version.h	Tue May 21 11:01:17 1996
--- myzsh-2.6-beta19a/Src/version.h	Fri May 24 16:02:43 1996
***************
*** 1 ****
! #define ZSH_VERSION "2.6-beta19"
--- 1 ----
! #define ZSH_VERSION "2.6-beta19a"
diff -r -c zsh-2.6-beta19/Src/zle_misc.c myzsh-2.6-beta19a/Src/zle_misc.c
*** zsh-2.6-beta19/Src/zle_misc.c	Tue May 21 11:24:41 1996
--- myzsh-2.6-beta19a/Src/zle_misc.c	Fri May 24 16:15:00 1996
***************
*** 1022,1027 ****
--- 1022,1038 ----
  		    ss++;
  		stradd(ss);
  		break;
+ 	    /* gjb added this */
+ 	    case 'H':
+ 	        if (curhist > 0) {
+ 		    char *sz = qgetevent(curhist-1);
+ 		    if (sz != 0) {
+ 		        stradd(sz);
+ 			if (*(bp-1) == '\n' || *(bp-1)=='\r')
+ 			    bp--;
+ 		    }
+ 		}
+ 		break;
  	    case 'h':
  	    case '!':
  		addbufspc(DIGBUFSIZE);

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

* Re: Zsh "POSTPROMPT" Feature
  1996-05-25 17:20 Zsh "POSTPROMPT" Feature Greg J. Badros
@ 1996-05-25 23:01 ` Andrew J Cosgriff
  1996-05-26  0:33   ` Hrvoje Niksic
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew J Cosgriff @ 1996-05-25 23:01 UTC (permalink / raw)
  To: Greg J. Badros; +Cc: zsh-workers


"Greg J. Badros" <gjb@moa.cs.duke.edu> wrote:
>  One feature that I've not seen talked about but that would be useful
>(mostly in an X environment) is the addition of a POSTPROMPT variable.  I
>have patches for zsh-2.5.03 that implement this, and then my .zshrc sets 
>my POSTPROMPT to
>{%^[]0;%H^G%}
>(Where ^[ is ESC, ^G is Ctrl-G-- the xterm sequence for setting the title
>and icon). [The %H is a change to print the last/current history item].

Well, if you just want to keep track of your current directory in your title bar, there's no need to patch zsh...For a start it's a little more efficient to only change your xterm title when you need to - ie. when you change directory - this can be done with the "chpwd" function, like so :

chpwd () {
        local dir=`print -D ${PWD}`
        local title=${LOGNAME}@$(uname -n):$dir
        print -n -D -P "\033]2;${title}\007"
}

Enjoy,
 Andrew.
-- 
 - Andrew J Cosgriff - ajc@bing.wattle.id.au -          Mobile : +61-14-856-122
 SysAdmin / Support Dude, UNICO Computer Systems    PGP & MIME ok and preferred
                        "Your future is encoded in Pi."





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

* Re: Zsh "POSTPROMPT" Feature
  1996-05-25 23:01 ` Andrew J Cosgriff
@ 1996-05-26  0:33   ` Hrvoje Niksic
  0 siblings, 0 replies; 3+ messages in thread
From: Hrvoje Niksic @ 1996-05-26  0:33 UTC (permalink / raw)
  To: zsh-workers

In your mail, you said:
> Well, if you just want to keep track of your current directory in your
> title bar, there's no need to patch zsh...For a start it's a little more
> efficient to only change your xterm title when you need to - ie. when you
[...]

Furthermore, I do not see why precmd couldn't be used. Admittedly, it is run
*before* prompt, instead of after, but in case of a simple cd command, I
fail to see the difference (the title will be changed before the next
command, which is quite the same as being changed after the current one).

> change directory - this can be done with the "chpwd" function, like so :

In case of directory title in an xterm, this is the most efficient solution.

-- 
hniksic@srce.hr              |  Student of electrical engineering
hniksic@fly.cc.fer.hr        |  University of Zagreb, Croatia
------------------------------------------------------------------
`VI' - An editor used by those heretics that don't subscribe to
       the Emacs religion.



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

end of thread, other threads:[~1996-05-26  0:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-25 17:20 Zsh "POSTPROMPT" Feature Greg J. Badros
1996-05-25 23:01 ` Andrew J Cosgriff
1996-05-26  0:33   ` Hrvoje Niksic

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