From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13211 invoked by alias); 30 May 2015 00:17:07 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20238 Received: (qmail 6016 invoked from network); 30 May 2015 00:17:04 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=L31P4Ejvbody7avgcN+7QzuRnpc+ft+7OrsWoko54q4=; b=lV3BLELkV3B2+Nrb3+1ZY0/IksX8yVzH4afAY49WCNsB0oduUDDcS+1MiRJANBChQg ssD86EU5LFWGCN20x9l7GwkqXLee8yKSCAe9HEYcAAA7bR5qKpUu4TaJp4naSBpik7CN qsxgYTGktPB6tjBP1kqeS5p/5WeJrCfB+eeeP8uq1Sqkv6iwaS+qEB0pjstBhEyy/eMf LxXfrPv5u/mUMVy2fP1SD++/ssosXNVGIHXhB0RaFjWkC2/nz8wMX9lYVYW6LNgdQVBh PFV9P7I3srLp1Bys8vTDqT5fWgNgl4S29XSjR+k2mAeU7hYcwfm/J/zIfFN29gvd0gHv nSHw== X-Gm-Message-State: ALoCoQk7fkMAkUsUNEzGmVy1V7zwRRAiLIwTVw68f2vuAcd7vGO6buI1oUP9hyDSOTLGhEfOZyT1 X-Received: by 10.202.214.132 with SMTP id n126mr1111597oig.75.1432945020848; Fri, 29 May 2015 17:17:00 -0700 (PDT) From: Bart Schaefer Message-Id: <150529171657.ZM15077@torch.brasslantern.com> Date: Fri, 29 May 2015 17:16:57 -0700 In-Reply-To: <87r3q7nzkr.fsf@gmail.com> Comments: In reply to Christian Neukirchen "Finding the first history event of the current instance" (May 23, 4:22pm) References: <87r3q7nzkr.fsf@gmail.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: Finding the first history event of the current instance MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On May 23, 4:22pm, Christian Neukirchen wrote: } } How can I list *only* the history lines that I typed into the current } session? For this, it would be enough to find the first event of the } new instance, but $HISTCMD is not set at .zshrc yet. I presume this means you have INC_APPEND_HISTORY but not SHARE_HISTORY. Probably the easiest approach would be to save a timestamp in your startup files and then use "history -d" piped to something that filters out the entries older than the timestamp. Next best would be to stash $HISTCMD in another variable from your zle-line-init widget, which requires making sure you don't stash it anew every time zle-line-init is called. Or there's this patch. I didn't add an option for listing only the NON-local history, but it should be pretty obvious how to do so. The patch got a little longer because I fixed what I consider to be a bug, which is that "fc -m nonmatchingpattern" would invoke the editor on an empty file instead of printing a warning. diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index f8e4edf..1fcc7c2 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -662,8 +662,8 @@ findex(fc) cindex(history, editing) cindex(editing history) redef(SPACES)(0)(tt(ifztexi(NOTRANS(@ @ @ @ @ @ ))ifnztexi( ))) -xitem(tt(fc) [ tt(-e) var(ename) ] [ tt(-m) var(match) ] [ var(old)tt(=)var(new) ... ] [ var(first) [ var(last) ] ]) -xitem(tt(fc -l )[ tt(-nrdfEiD) ] [ tt(-t) var(timefmt) ] [ tt(-m) var(match) ]) +xitem(tt(fc) [ tt(-e) var(ename) ] [-L] [ tt(-m) var(match) ] [ var(old)tt(=)var(new) ... ] [ var(first) [ var(last) ] ]) +xitem(tt(fc -l )[ tt(-LnrdfEiD) ] [ tt(-t) var(timefmt) ] [ tt(-m) var(match) ]) xitem(SPACES()[ var(old)tt(=)var(new) ... ] [ var(first) [ var(last) ] ]) xitem(tt(fc -p )[ tt(-a) ] [ var(filename) [ var(histsize) [ var(savehistsize) ] ] ]) xitem(tt(fc) tt(-P)) @@ -683,11 +683,15 @@ A string specifies the most recent event beginning with the given string. All substitutions var(old)tt(=)var(new), if any, are then performed on the commands. -If the tt(-l) flag is given, the resulting commands are listed on -standard output. -If the tt(-m) flag is also given the first argument is taken as a +If the tt(-L) flag is given, only the local history is considered (see +tt(SHARE_HISTORY) in ifzman(zmanref(zshoptions))\ +ifnzman(noderef(Description of Options))). +If the tt(-m) flag is given, the first argument is taken as a pattern (should be quoted) and only the history events matching this -pattern will be shown. +pattern are considered. + +When the tt(-l) flag is given, the resulting commands are listed on +standard output. Otherwise the editor program var(ename) is invoked on a file containing these history events. If var(ename) is not given, the value of the parameter tt(FCEDIT) is used; if that is not set the value of the diff --git a/Src/builtin.c b/Src/builtin.c index 18c22f2..9358e8b 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -69,7 +69,7 @@ static struct builtin builtins[] = * But that's actually not useful, so it's more consistent to * cause an error. */ - BUILTIN("fc", 0, bin_fc, 0, -1, BIN_FC, "aAdDe:EfiIlmnpPrRt:W", NULL), + BUILTIN("fc", 0, bin_fc, 0, -1, BIN_FC, "aAdDe:EfiIlLmnpPrRt: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, "kmMtTuUz", NULL), @@ -81,7 +81,7 @@ static struct builtin builtins[] = BUILTIN("hashinfo", 0, bin_hashinfo, 0, 0, 0, NULL, NULL), #endif - BUILTIN("history", 0, bin_fc, 0, -1, BIN_FC, "adDEfimnpPrt:", "l"), + BUILTIN("history", 0, bin_fc, 0, -1, BIN_FC, "adDEfiLmnpPrt:", "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), @@ -104,7 +104,7 @@ static struct builtin builtins[] = BUILTIN("pushd", BINF_SKIPINVALID | BINF_SKIPDASH | BINF_DASHDASHVALID, bin_cd, 0, 2, BIN_PUSHD, "qsPL", NULL), BUILTIN("pushln", 0, bin_print, 0, -1, BIN_PRINT, NULL, "-nz"), BUILTIN("pwd", 0, bin_pwd, 0, 0, 0, "rLP", NULL), - BUILTIN("r", 0, bin_fc, 0, -1, BIN_R, "nrl", NULL), + BUILTIN("r", 0, bin_fc, 0, -1, BIN_R, "nrlL", NULL), BUILTIN("read", 0, bin_read, 0, -1, 0, "cd:ek:%lnpqrst:%zu:AE", NULL), BUILTIN("readonly", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "AE:%F:%HL:%R:%TUZ:%afghi:%lptux", "r"), BUILTIN("rehash", 0, bin_hash, 0, 0, 0, "df", "r"), @@ -1689,9 +1689,6 @@ fclist(FILE *f, Options ops, zlong first, zlong last, fclose(f); return 1; } - /* suppress "no substitution" warning if no substitution is requested */ - if (!subs) - fclistdone = 1; ent = gethistent(first, first < last? GETHIST_DOWNWARD : GETHIST_UPWARD); if (!ent || (first < last? ent->histnum > last : ent->histnum < last)) { @@ -1726,11 +1723,14 @@ fclist(FILE *f, Options ops, zlong first, zlong last, } for (;;) { - s = dupstring(ent->node.nam); + if (!OPT_ISSET(ops,'L') || !(ent->node.flags & HIST_FOREIGN)) + s = dupstring(ent->node.nam); + else + s = NULL; /* this if does the pattern matching, if required */ - if (!pprog || pattry(pprog, s)) { + if (s && (!pprog || pattry(pprog, s))) { /* perform substitution */ - fclistdone |= fcsubs(&s, subs); + fclistdone |= (subs ? fcsubs(&s, subs) : 1); /* do numbering */ if (!OPT_ISSET(ops,'n')) { @@ -1780,7 +1780,10 @@ fclist(FILE *f, Options ops, zlong first, zlong last, if (f != stdout) fclose(f); if (!fclistdone) { - zwarnnam("fc", "no substitutions performed"); + if (subs) + zwarnnam("fc", "no substitutions performed"); + else if (OPT_ISSET(ops,'L') || pprog) + zwarnnam("fc", "no matching events found"); return 1; } return 0; -- Barton E. Schaefer