From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24488 invoked from network); 26 Feb 2009 15:53:11 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 26 Feb 2009 15:53:11 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 54993 invoked from network); 26 Feb 2009 15:53:02 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 26 Feb 2009 15:53:02 -0000 Received: (qmail 24718 invoked by alias); 26 Feb 2009 15:52:57 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26613 Received: (qmail 24704 invoked from network); 26 Feb 2009 15:52:56 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 26 Feb 2009 15:52:56 -0000 Received: from cluster-d.mailcontrol.com (cluster-d.mailcontrol.com [85.115.60.190]) by bifrost.dotsrc.org (Postfix) with ESMTPS id BB8068058F83 for ; Thu, 26 Feb 2009 16:52:51 +0100 (CET) Received: from cameurexb01.EUROPE.ROOT.PRI ([193.128.72.68]) by rly05d.srv.mailcontrol.com (MailControl) with ESMTP id n1QFqkPg000841 for ; Thu, 26 Feb 2009 15:52:50 GMT Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Thu, 26 Feb 2009 15:52:47 +0000 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.14.2/8.13.4) with ESMTP id n1QFqlBt010370 for ; Thu, 26 Feb 2009 15:52:47 GMT Received: from csr.com (pws@localhost) by news01.csr.com (8.14.2/8.14.2/Submit) with ESMTP id n1QFqkBA010367 for ; Thu, 26 Feb 2009 15:52:46 GMT X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: add -t option to history X-Mailer: MH-E 8.0.3; nmh 1.3; GNU Emacs 22.1.1 Date: Thu, 26 Feb 2009 15:52:46 +0000 Message-ID: <10366.1235663566@csr.com> From: Peter Stephenson X-OriginalArrivalTime: 26 Feb 2009 15:52:47.0403 (UTC) FILETIME=[4536AFB0:01C9982A] X-Scanned-By: MailControl A_08_51_00 (www.mailcontrol.com) on 10.68.0.115 X-Virus-Scanned: ClamAV 0.92.1/9051/Thu Feb 26 14:08:01 2009 on bifrost X-Virus-Status: Clean I needed a new strftime extension for months without a leading blank or zero; does anyone know if %N is used elsewhere as an extension (it's not in POSIX)? Index: Doc/Zsh/builtins.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v retrieving revision 1.120 diff -u -r1.120 builtins.yo --- Doc/Zsh/builtins.yo 12 Feb 2009 09:56:26 -0000 1.120 +++ Doc/Zsh/builtins.yo 26 Feb 2009 15:49:40 -0000 @@ -484,7 +484,9 @@ findex(fc) cindex(history, editing) cindex(editing history) -xitem(tt(fc) [ tt(-e) var(ename) ] [ tt(-nlrdDfEim) ] [ var(old)tt(=)var(new) ... ] [ var(first) [ var(last) ] ]) +xitem(tt(fc) [ tt(-e) var(ename) ] [ tt(-m) var(match) ] [ var(old)tt(=)var(new) ... ] [ var(first) [ var(last) ] ]) +xitem(tt(fc) tt(-l) [ tt(-nrdfEiD) ] [ tt(-t) var(timefmt) ] [ tt(-m) var(match) ]) +xitem( [ var(old)tt(=)var(new) ... ] [ var(first) [ var(last) ] ]) xitem(tt(fc) tt(-p) [ tt(-a) ] [ var(filename) [ var(histsize) [ var(savehistsize) ] ] ]) xitem(tt(fc) tt(-P)) item(tt(fc) tt(-ARWI) [ var(filename) ])( @@ -517,13 +519,26 @@ The flag tt(-r) reverses the order of the commands and the flag tt(-n) suppresses command numbers when listing. -Also when listing, tt(-d) prints timestamps for each command, and -tt(-f) prints full time-date stamps. Adding the tt(-E) flag -causes the dates to be printed as `var(dd)tt(.)var(mm)tt(.)var(yyyy)', -instead of the default `var(mm)tt(/)var(dd)tt(/)var(yyyy)'. -Adding the tt(-i) flag causes the dates to be printed in ISO8601 -`var(yyyy)tt(-)var(mm)tt(-)var(dd)' format. -With the tt(-D) flag, tt(fc) prints elapsed times. + +Also when listing, +startsitem() +sitem(tt(-d))(prints timestamps for each command) +sitem(tt(-f))(prints full time-date stamps in the US +`var(MM)tt(/)var(DD)tt(/)var(YY) var(hh):var(mm)' format) +sitem(tt(-E))(prints full time-date stamps in the European +`var(dd)tt(.)var(mm)tt(.)var(yyyy) var(hh):var(mm)' format) +sitem(tt(-i))(prints full time-date stamps in ISO8601 +`var(yyyy)tt(-)var(mm)tt(-)var(dd) var(hh):var(mm)' format) +sitem(tt(-t) var(fmt))(prints time and date stamps in the given format; +var(fmt) is formatted with the strftime function with the zsh extensions +described for the tt(%D{)var(string)tt(}) prompt format in +ifzman(the section EXPANSION OF PROMPT SEQUENCES in zmanref(zshmisc))\ +ifnzman(noderef(Prompt Expansion)). The resulting formatted string must be +no more than 256 characters or will not be printed. +) +sitem(tt(-D))(prints elapsed times; may be combined with one of the +options above.) +endsitem() cindex(history, stack) cindex(stack, history) Index: Doc/Zsh/calsys.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/calsys.yo,v retrieving revision 1.15 diff -u -r1.15 calsys.yo --- Doc/Zsh/calsys.yo 10 Dec 2008 13:30:27 -0000 1.15 +++ Doc/Zsh/calsys.yo 26 Feb 2009 15:49:40 -0000 @@ -613,9 +613,11 @@ kindex(date-format) item(tt(date-format))( A tt(strftime) format string (see manref(strftime)(3)) with the zsh -extensions tt(%f) for a day of the month with no leading zero or space -for single digits, and tt(%k) or tt(%l) for the hour of the day on the 24- -or 12-hour clock, again with no leading zero or space for single digits. +extensions providing various numbers with no leading zero or space +if the number is a single digit as described for the +tt(%D{)var(string)tt(}) prompt format in +ifzman(the section EXPANSION OF PROMPT SEQUENCES in zmanref(zshmisc))\ +ifnzman(noderef(Prompt Expansion)). This is used for outputting dates in tt(calendar), both to support the tt(-v) option and when adding recurring events back to the calendar Index: Doc/Zsh/prompt.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/prompt.yo,v retrieving revision 1.16 diff -u -r1.16 prompt.yo --- Doc/Zsh/prompt.yo 16 Sep 2008 15:04:44 -0000 1.16 +++ Doc/Zsh/prompt.yo 26 Feb 2009 15:49:40 -0000 @@ -171,11 +171,16 @@ ) item(tt(%D{)var(string)tt(}))( var(string) is formatted using the tt(strftime) function. -See manref(strftime)(3) for more details. Three additional codes are -available: tt(%f) prints the day of the month, like tt(%e) but -without any preceding space if the day is a single digit, and -tt(%K)/tt(%L) correspond to tt(%k)/tt(%l) for the hour of the day -(24/12 hour clock) in the same way. +See manref(strftime)(3) for more details. Various zsh +extensions provide numbers with no leading zero or space +if the number is a single digit: + +startsitem() +sitem(tt(%f))(a day of the month) +sitem(tt(%k))(the hour of the day on the 24-hour clock) +sitem(tt(%l))(the hour of the day on the 12-hour clock) +sitem(tt(%N))(the month where January is 1.) +endsitem() ) enditem() Index: Src/builtin.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v retrieving revision 1.221 diff -u -r1.221 builtin.c --- Src/builtin.c 25 Feb 2009 10:24:01 -0000 1.221 +++ Src/builtin.c 26 Feb 2009 15:49:40 -0000 @@ -69,7 +69,7 @@ * But that's actually not useful, so it's more consistent to * cause an error. */ - BUILTIN("fc", 0, bin_fc, 0, -1, BIN_FC, "nlre:IRWAdDfEimpPa", NULL), + BUILTIN("fc", 0, bin_fc, 0, -1, BIN_FC, "aAdDe:EfiIlmnpPrRt:W", NULL), BUILTIN("fg", 0, bin_fg, 0, -1, BIN_FG, NULL, NULL), BUILTIN("float", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "E:%F:%HL:%R:%Z:%ghlprtux", "E"), BUILTIN("functions", BINF_PLUSOPTS, bin_functions, 0, -1, 0, "kmMtuUz", NULL), @@ -81,7 +81,7 @@ BUILTIN("hashinfo", 0, bin_hashinfo, 0, 0, 0, NULL, NULL), #endif - BUILTIN("history", 0, bin_fc, 0, -1, BIN_FC, "nrdDfEimpPa", "l"), + BUILTIN("history", 0, bin_fc, 0, -1, BIN_FC, "adDEfimnpPrt:", "l"), BUILTIN("integer", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "HL:%R:%Z:%ghi:%lprtux", "i"), BUILTIN("jobs", 0, bin_fg, 0, -1, BIN_JOBS, "dlpZrs", NULL), BUILTIN("kill", BINF_HANDLES_OPTS, bin_kill, 0, -1, 0, NULL, NULL), @@ -1599,7 +1599,7 @@ { int fclistdone = 0; zlong tmp; - char *s; + char *s, *tdfmt, *timebuf; Histent ent; /* reverse range if required */ @@ -1625,6 +1625,25 @@ return 1; } + if (OPT_ISSET(ops,'d') || OPT_ISSET(ops,'f') || + OPT_ISSET(ops,'E') || OPT_ISSET(ops,'i') || + OPT_ISSET(ops,'t')) { + if (OPT_ISSET(ops,'t')) { + tdfmt = OPT_ARG(ops,'t'); + } else if (OPT_ISSET(ops,'i')) { + tdfmt = "%Y-%m-%d %H:%M"; + } else if (OPT_ISSET(ops,'E')) { + tdfmt = "%f.%N.%Y %H:%M"; + } else if (OPT_ISSET(ops,'f')) { + tdfmt = "%N/%f/%Y %H:%M"; + } else { + tdfmt = "%H:%M"; + } + timebuf = zhalloc(256); + } else { + tdfmt = timebuf = NULL; + } + for (;;) { s = dupstring(ent->node.nam); /* this if does the pattern matching, if required */ @@ -1641,24 +1660,11 @@ } /* output actual time (and possibly date) of execution of the command, if required */ - if (OPT_ISSET(ops,'d') || OPT_ISSET(ops,'f') || - OPT_ISSET(ops,'E') || OPT_ISSET(ops,'i')) { + if (tdfmt != NULL) { struct tm *ltm; ltm = localtime(&ent->stim); - if (OPT_ISSET(ops,'i')) { - fprintf(f, "%d-%02d-%02d ", - ltm->tm_year + 1900, - ltm->tm_mon + 1, ltm->tm_mday); - } else if (OPT_ISSET(ops,'E')) { - fprintf(f, "%d.%d.%d ", - ltm->tm_mday, ltm->tm_mon + 1, - ltm->tm_year + 1900); - } else if (OPT_ISSET(ops,'f')) { - fprintf(f, "%d/%d/%d ", - ltm->tm_mon + 1, ltm->tm_mday, - ltm->tm_year + 1900); - } - fprintf(f, "%02d:%02d ", ltm->tm_hour, ltm->tm_min); + if (ztrftime(timebuf, 256, tdfmt, ltm)) + fprintf(f, "%s ", timebuf); } /* display the time taken by the command, if required */ if (OPT_ISSET(ops,'D')) { Index: Src/utils.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.209 diff -u -r1.209 utils.c --- Src/utils.c 19 Feb 2009 10:15:10 -0000 1.209 +++ Src/utils.c 26 Feb 2009 15:49:40 -0000 @@ -2486,7 +2486,9 @@ *buf++ = '0' + (hr12 % 10); break; case 'm': - *buf++ = '0' + (tm->tm_mon + 1) / 10; + case 'N': + if (tm->tm_mon > 8 || fmt[-1] == 'm') + *buf++ = '0' + (tm->tm_mon + 1) / 10; *buf++ = '0' + (tm->tm_mon + 1) % 10; break; case 'M': -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070