zsh-users
 help / color / mirror / code / Atom feed
From: Greg Klanderman <gak@klanderman.net>
To: zsh-users@zsh.org
Subject: Re: additionally saving history for each directory?
Date: Tue, 22 Dec 2020 11:00:43 -0500	[thread overview]
Message-ID: <877dp9omok.fsf@lwm.klanderman.net> (raw)
In-Reply-To: <CAH+w=7bVbYNqSHzWAtJ36f5s4WYn+YGJW-oWk8ppPkQtQQ70rw@mail.gmail.com> (Bart Schaefer's message of "Sun, 20 Dec 2020 14:32:59 -0800")

Thanks Bart!

>>>>> On December 20, 2020 Bart Schaefer <schaefer@brasslantern.com> 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


  reply	other threads:[~2020-12-22 16:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-20 22:19 Greg Klanderman
2020-12-20 22:32 ` Bart Schaefer
2020-12-22 16:00   ` Greg Klanderman [this message]
2021-01-12 16:47     ` Greg Klanderman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877dp9omok.fsf@lwm.klanderman.net \
    --to=gak@klanderman.net \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).