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

Changing "0" as a history-line reference



I'm curious what people think about making a "0" in a history-line
reference man the last line in the history instead of the first?
Currently "0" is synonymous with "1".  Since -1 is "last minus one", I
was thinking that it might make more sense to have "0" mean "last".

For instance, "history -99 0" would output the last 100 lines of the
history, including the very last command (which might be a script that
actually called the history command).  The user could currently use
something like "999999" instead of "0", so this is not really that big
of a deal, but I like it.

Here's the simple patch.

..wayne..

---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Doc/Zsh/builtins.yo
--- Doc/Zsh/builtins.yo	10 May 2002 09:52:25 -0000	1.45
+++ Doc/Zsh/builtins.yo	13 May 2002 22:23:54 -0000
@@ -369,7 +369,7 @@
 Select a range of commands from var(first) to var(last) from the
 history list.
 The arguments var(first) and var(last) may be specified as a
-number or as a string.  A negative number is used as an offset
+number or as a string.  A non-positive number is used as an offset
 to the current history event number.
 A string specifies the most recent event beginning with the given string.
 All substitutions var(old)tt(=)var(new), if any, are then performed
Index: Src/builtin.c
--- Src/builtin.c	24 Mar 2002 07:56:42 -0000	1.73
+++ Src/builtin.c	13 May 2002 22:23:55 -0000
@@ -1389,10 +1389,10 @@
 {
     int cmd;
 
-    /* First try to match a history number.  Negative *
+    /* First try to match a history number.  Non-positive *
      * numbers indicate reversed numbering.           */
     if ((cmd = atoi(s)) != 0 || *s == '0') {
-	if (cmd < 0)
+	if (cmd <= 0)
 	    cmd = addhistnum(curline.histnum,cmd,HIST_FOREIGN);
 	if (cmd < 0)
 	    cmd = 0;
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---



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