Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: An example of writing a custom history file?



On Mon, 15 Dec 2014 19:34:52 +0100
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> I found only one place in the manpage that mentions history only being
> active in an interactive shell, perhaps it should be clearer about it?
> I also noticed that explicit fc -l and fc -W etc do nothing but also
> don't print a warning when invoked non-interactively.

Yes, this is definitely wrong.  (Further discussion on this can
go on zsh-workers but I wanted to respond initially here.)

Here are a couple of places where it could be mentioned.  The roadmap
entry deliberately does not go into the gory subject of turning
on the interactive option for scripts.  (Yes, it's not a roadmap,
it's an overview, in current corporate jargon.)

By the way, I'm entirely open to making fc read and write history in
non-interactive shells if we can manage that, but obviously it would
need some work.

diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 4463123..38788d3 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -657,6 +657,12 @@ xitem(tt(      )[ 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) ])(
+The tt(fc) command controls the interactive history mechanism.  Note
+that reading and writing of history options is only performed if the
+shell is interactive.  Usually this is detected automatically, but
+it can be forced by setting the tt(interactive) option when starting the
+shell.
+
 Select a range of commands from var(first) to var(last) from the
 history list.
 The arguments var(first) and var(last) may be specified as a
diff --git a/Doc/Zsh/roadmap.yo b/Doc/Zsh/roadmap.yo
index ba598e5..6778489 100644
--- a/Doc/Zsh/roadmap.yo
+++ b/Doc/Zsh/roadmap.yo
@@ -41,7 +41,9 @@ set appropriate variables, and the number of history lines retained by
 default is quite small (30 lines).  See the description of the shell
 variables (referred to in the documentation as parameters) tt(HISTFILE),
 tt(HISTSIZE) and tt(SAVEHIST) in ifzman(zmanref(zshparam))\
-ifnzman(noderef(Parameters Used By The Shell)).
+ifnzman(noderef(Parameters Used By The Shell)).  Note that it's
+currently only possible to read and write files saving history
+when the shell is interactive, i.e. it does not work from scripts.
 
 The shell now supports the UTF-8 character set (and also others if
 supported by the operating system).  This is (mostly) handled transparently

pws



Messages sorted by: Reverse Date, Date, Thread, Author