about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2015-05-30 15:22:09 -0700
committerBarton E. Schaefer <schaefer@zsh.org>2015-05-30 15:22:09 -0700
commit911edc5ea475bdf679feee7c800369d8285c263d (patch)
tree8ad6f9f7932325456a3bc32d5aee697a6c9871a9
parentfea56dc32b8cf00715e1c55fbfccdadfc5c48e06 (diff)
downloadzsh-911edc5ea475bdf679feee7c800369d8285c263d.tar.gz
zsh-911edc5ea475bdf679feee7c800369d8285c263d.tar.xz
zsh-911edc5ea475bdf679feee7c800369d8285c263d.zip
users/20238: add "fc -L" to operate only on the local shell history
Also avoid invoking the editor on empty results.
-rw-r--r--ChangeLog6
-rw-r--r--Doc/Zsh/builtins.yo16
-rw-r--r--Src/builtin.c23
3 files changed, 29 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 174618aa3..681975a05 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-05-30  Barton E. Schaefer  <schaefer@zsh.org>
+
+	* users/20238: Doc/Zsh/builtins.yo, Src/builtin.c: add "fc -L" to
+	operate only on the local shell history when history sharing is
+	in effect.  Also avoid invoking the editor on empty results.
+
 2015-05-30  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
 	* Han Pingtian: 35324: Functions/Zftp/zfget_match: better zfget
diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index f8e4edf91..1fcc7c2b7 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 18c22f29e..9358e8b1f 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;