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

Zsh "POSTPROMPT" Feature



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@xxxxxxxxxxx                Seattle, WA  98103-4067
http://www.cs.duke.edu/~gjb    voice 206/528.7513   fax 206/523.9328

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


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