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, 12 Jan 2021 11:47:55 -0500	[thread overview]
Message-ID: <878s8yksp0.fsf@lwm.klanderman.net> (raw)
In-Reply-To: <877dp9omok.fsf@lwm.klanderman.net> (Greg Klanderman's message of "Tue, 22 Dec 2020 11:00:43 -0500")

>>>>> On December 22, 2020 Greg Klanderman <gak@klanderman.net> wrote:

> 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'}
> }

Hi all, realize this probably got overlooked during the holidays..
should it work to do it this way as well as the suggestion in the zsh
manual, i.e.

zshaddhistory() {
  print -sr -- ${1%%$?\n?}
  fc -p .zsh_local_history
}

which prints to the normal history, then switches to the local history
and relies on the normal save to save to the now default local
history.

My version is trying to write directly to the local history file from
the hook, then allow the normal history save to go to the normal
history file.  My version is creating the local history file, but
nothing gets written.  The normal history is updated.

Also if anyone has any key bindings for searching/traversing an
alternate local history file please post!

thanks,
Greg

> 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:[~2021-01-12 16:50 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
2021-01-12 16:47     ` Greg Klanderman [this message]

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=878s8yksp0.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).