Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: An example of writing a custom history file?
Making the change suggested, adding 1000 doesn't change the behavior - no
file is written. Again, here is the entire 12-line program:
#!/usr/bin/zsh
fc -ap /tmp/example_history 1000
local line
# Read lines and add them to history
while vared -h -p "hey: " line
do
[[ $line == 'quit' ]] && exit 0
# The -s option below adds the line to the history
print -s $line
line=''
done
As to reading docs, I've gone over
http://zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html and
http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-System-Configuration
and https://github.com/johan/zsh/blob/master/Functions/Misc/sticky-note way
more times than I want or normally have to do to get corresponding
information in programming systems. And still without success.
In the first doc for built-in commands, 1000, the histsize parameter is
optional and is taken from HISTSIZE and SAVEHIST if those parameters are
not given. My HISTSIZE and SAVEHIST are 1000.
What is sorely missing, and I've also looked at
http://zsh.sourceforge.net/Guide/zshguide.html, are some *SIMPLE* examples
like the program above. In fact it would be great if a corrected version of
the above could be included in the User Guide.
When the basic history mechanism isn't working, it doesn't help to pour
over a 138-line program that performs several functions in one program,
adds key bindings, beeps at the terminal, has color themes, and uses some
sort of "{ } aways { }" construct that probably is a Zsh extension and not
POSIX shell construct.
That program is a great as an example of a finished zsh program. But for
learning purposes, even variable interpolation as in
fc -ap $stickyfile $stickysize $stickysize
instead of:
fc -ap /tmp/example_history 1000
is a distraction.
is a distraction.
On Mon, Dec 15, 2014 at 11:14 AM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
wrote:
> On Dec 15, 9:26am, Rocky Bernstein wrote:
> }
> } Almost there! The only remaining problem is now how write the accumulated
> } history. For that, I assume I use fc -W *filename* or fc -A *filename*.
>
> I don't really mind helping you out here, but if you were to actually
> read the documentation for the "fc" command or even look more closely
> at the way it's used in sticky-note you should be able to figure this
> out for yourself.
>
> } #!/usr/bin/zsh
> } fc -ap /tmp/example_history 1000
>
> You need to supply another argument to "fc -ap" telling it what the
> maximum size of the saved file is. Then that number of lines will
> be saved automatically when the current function goes out of scope.
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author