Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Finding the first history event of the current instance
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author