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

Re: additionally saving history for each directory?



Thanks Bart!

>>>>> On December 20, 2020 Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:

> There's a patch set in workers/45326 that never got much review.

I don't think that was it, but interesting..

> However, the very simple example is in the zsh documentation under
> "zshaddhistory".

Hmm maybe that's what I saw.. I had been browsing the zsh manual
recently, though I thought there were also some example key bindings.

So if I add a hook something like the following to
zshaddhistory_functions:

save_per_directory_history () {
  setopt localoptions incappendhistory
  fc -p -a .zsh_local_history 1000
  print -sr -- ${1%%$'\n'}
}

that should also work?  Seems a little cleaner to write to the per-
directory history file from the hook, and rely on the normal history
writing mechanism to write to the normal history.

Should I 'return 0' to be sure that the normal history is updated, to
guard against the off chance the print might return an error?

Also in practice I'll write the local history to
~/.zsh-local-history/${PWD//\//##} or something like that to keep them
all in one place and avoid littering the filesystem.

So this will incur the cost of reading the per- directory history file
on every command execution?  Or does zsh internally cache some number
of recent history file sets?

Hmm I see the local history files getting created, but they are all
empty and remain so as I run various commands.  I added a print of $1
in the hook and it does contain the command being run as expected.
What am I doing wrong?

thank you,
Greg




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