zsh-users
 help / color / mirror / Atom feed
* additionally saving history for each directory?
@ 2020-12-20 22:19 Greg Klanderman
  2020-12-20 22:32 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Klanderman @ 2020-12-20 22:19 UTC (permalink / raw)
  To: Zsh Users


I feel like somewhat recently someone posted a few line example of
saving per-directory history, but I've been unable to find it.
Somehow that popped into my head earlier, and seemed like a useful
feature to additionally be saving history across shells to
directory-specific history files, and then have alternate key bindings
of eg. history-incremental-search-backward and
history-beginning-search-backward that search the history for the
current directory instead of the shell instance's history.  Anyone
have a simple recipe for something like that to get me started?

thank you,
Greg


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: additionally saving history for each directory?
  2020-12-20 22:19 additionally saving history for each directory? Greg Klanderman
@ 2020-12-20 22:32 ` Bart Schaefer
  2020-12-22 16:00   ` Greg Klanderman
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2020-12-20 22:32 UTC (permalink / raw)
  To: gak; +Cc: Zsh Users

On Sun, Dec 20, 2020 at 2:19 PM Greg Klanderman <gak@klanderman.net> wrote:
>
> I feel like somewhat recently someone posted a few line example of
> saving per-directory history, but I've been unable to find it.

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

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: additionally saving history for each directory?
  2020-12-20 22:32 ` Bart Schaefer
@ 2020-12-22 16:00   ` Greg Klanderman
  2021-01-12 16:47     ` Greg Klanderman
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Klanderman @ 2020-12-22 16:00 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: additionally saving history for each directory?
  2020-12-22 16:00   ` Greg Klanderman
@ 2021-01-12 16:47     ` Greg Klanderman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Klanderman @ 2021-01-12 16:47 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-12 16:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-20 22:19 additionally saving history for each directory? Greg Klanderman
2020-12-20 22:32 ` Bart Schaefer
2020-12-22 16:00   ` Greg Klanderman
2021-01-12 16:47     ` Greg Klanderman

zsh-users

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-users

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-users zsh-users/ http://inbox.vuxu.org/zsh-users \
		zsh-users@zsh.org
	public-inbox-index zsh-users

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


code repositories for the project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git