1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-10-02 17:01:19 +02:00

- Added the -p (push) and -P (pop) options to the "fc" builtin.

- Allow -p/-P to be given to "history".
- On exit, save & pop any pushed history stacks before we call the
  normal savehistfile() function.
This commit is contained in:
Wayne Davison 2004-05-20 22:22:43 +00:00
parent 3971345ee6
commit 76ec200cc4

@ -69,8 +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, "nlre:IRWAdDfEim",
NULL),
BUILTIN("fc", 0, bin_fc, 0, -1, BIN_FC, "nlre:IRWAdDfEimpP", 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:%Hghlprtux", "E"),
BUILTIN("functions", BINF_PLUSOPTS, bin_functions, 0, -1, 0, "kmtuUz", NULL),
@ -82,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, "nrdDfEim", "l"),
BUILTIN("history", 0, bin_fc, 0, -1, BIN_FC, "nrdDfEimpP", "l"),
BUILTIN("integer", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "Hghi:%lprtux", "i"),
BUILTIN("jobs", 0, bin_fg, 0, -1, BIN_JOBS, "dlpZrs", NULL),
BUILTIN("kill", 0, bin_kill, 0, -1, 0, NULL, NULL),
@ -1308,6 +1307,43 @@ bin_fc(char *nam, char **argv, Options ops, int func)
zwarnnam(nam, "not interactive shell", NULL, 0);
return 1;
}
if (OPT_ISSET(ops,'p')) {
char *hf = "";
int hs = DEFAULT_HISTSIZE;
int shs = 0;
if (*argv) {
hf = *argv++;
if (*argv) {
hs = atoi(*argv++);
if (*argv)
shs = atoi(*argv++);
else
shs = hs;
if (*argv) {
zwarnnam("fc", "too many arguments", NULL, 0);
return 1;
}
} else {
hs = histsiz;
shs = savehistsiz;
}
}
if (!pushhiststack(hf, hs, shs))
return 1;
if (*hf) {
struct stat st;
if (stat(hf, &st) >= 0 || errno != ENOENT)
readhistfile(hf, 1, HFILE_USE_OPTIONS);
}
return 0;
}
if (OPT_ISSET(ops,'P')) {
if (*argv) {
zwarnnam("fc", "too many arguments", NULL, 0);
return 1;
}
return !saveandpophiststack(-1);
}
/* with the -m option, the first argument is taken *
* as a pattern that history lines have to match */
if (*argv && OPT_ISSET(ops,'m')) {
@ -4073,8 +4109,10 @@ zexit(int val, int from_where)
killrunjobs(from_where == 1);
}
if (isset(RCS) && interact) {
if (!nohistsave)
if (!nohistsave) {
saveandpophiststack(0);
savehistfile(NULL, 1, HFILE_USE_OPTIONS);
}
if (islogin && !subsh) {
sourcehome(".zlogout");
#ifdef GLOBAL_ZLOGOUT