zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: $history index in prompt_bart_precmd
@ 2000-04-08 20:55 Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2000-04-08 20:55 UTC (permalink / raw)
  To: zsh-workers

I finally exceeded my $HISTSIZE in one window and noticed that my prompt
was no longer updating.  $history behaves as an assoc indexed on the
current history number, which means it gets leading empty elements as
things fall off the front -- but $#history reflects the actual number of
non-empty elements, e.g. it's never more than $HISTSIZE-1.

There is, however, some kind of bug with interpretation of the keys for
$history, because e.g. $history[3-1] == $history[3].  (It should yield
the empty string, as there isn't any hash table value for key "3-1".)

Index: Functions/Prompts/prompt_bart_setup
===================================================================
@@ -57,8 +57,8 @@
     setopt localoptions noxtrace extendedglob noksharrays
 
     # Using psvar here protects against unwanted promptsubst expansions.
-    psvar[8]="$history[$#history]"	# Use history text, not just number
-    psvar[9]=''				# Padding before upper right prompt
+    psvar[8]="$history[$[${(%):-%h}-1]]" # Use history text, not just number
+    psvar[9]=''				 # Padding before upper right prompt
 
     repeat $[COLUMNS-${#${(%%f)${PS1//[%]\{[^%]#%\}/}}[1]}-1]
     do

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: PATCH: $history index in prompt_bart_precmd
@ 2000-04-10  8:20 Sven Wischnowsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 2000-04-10  8:20 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> ...
> 
> There is, however, some kind of bug with interpretation of the keys for
> $history, because e.g. $history[3-1] == $history[3].  (It should yield
> the empty string, as there isn't any hash table value for key "3-1".)

It was using atoi(). Yes, since this is supposed to be an assoc, we
should probably be more careful to check the index used.

Bye
 Sven

Index: Src/Modules/parameter.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/parameter.c,v
retrieving revision 1.2
diff -u -r1.2 parameter.c
--- Src/Modules/parameter.c	2000/04/01 20:49:48	1.2
+++ Src/Modules/parameter.c	2000/04/10 08:20:17
@@ -1020,6 +1020,8 @@
 {
     Param pm = NULL;
     Histent he;
+    char *p;
+    int ok = 1;
 
     pm = (Param) zhalloc(sizeof(struct param));
     pm->nam = dupstring(name);
@@ -1032,7 +1034,17 @@
     pm->ename = NULL;
     pm->old = NULL;
     pm->level = 0;
-    if ((he = quietgethist(atoi(name))))
+
+    if (*name != '0' || name[1]) {
+	if (*name == '0')
+	    ok = 0;
+	else {
+	    for (p = name; *p && idigit(*p); p++);
+	    if (*p)
+		ok = 0;
+	}
+    }
+    if (ok && (he = quietgethist(atoi(name))))
 	pm->u.str = dupstring(he->text);
     else {
 	pm->u.str = dupstring("");

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

end of thread, other threads:[~2000-04-10  8:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-08 20:55 PATCH: $history index in prompt_bart_precmd Bart Schaefer
2000-04-10  8:20 Sven Wischnowsky

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