z icon indicating copy to clipboard operation
z copied to clipboard

Several open shells won't synchronize history

Open ehogstrand opened this issue 6 years ago • 5 comments

When running several instances of PowerShell, z won't synchronize the history between them. Improvement would be to read history, before writing, so other instances history will be remembered and shared.

ehogstrand avatar Mar 20 '19 13:03 ehogstrand

This would involve reading the history file before every command is looked up.

Some type of cross process store would be more efficient.

badmotorfinger avatar Mar 22 '19 21:03 badmotorfinger

May I take a look into this?

gerardog avatar Jul 22 '23 22:07 gerardog

@gerardog - That would be great, I would appreciate it.

badmotorfinger avatar Jul 23 '23 00:07 badmotorfinger

Proposal: Modify the format of ".cdHistory" text file database, just a little bit, to use as cross process store.

Currently each line in that file represents a folder, its ranking and its last accessed date. The change is twofold:

  • Allow duplicate items: a Folder appearing twice with ranking 25 and also with rank 1, has an effective rank of 26.
  • Every process can append lines to the file (a read-append shared lock). For example: Every time you call 'z', you can add a line to increase the rank of a directory.
  • Also you would read the new lines added by other processes. Each process remembers it has read until position=$lastPosition. On each invocation, if the file size or timestamp has changed, we read only what's new from the file, optimizing the process.
  • This turns the db it into a journal-like structure. A cleanup or compression is needed every X. Possible trigger could be whenever you reading the DB and find more than ..(30?) repeated items. The cleanup consists of reading the whole file and rewriting with processed duplicates, and if size>$max_size (300?) eliminating items ranking below that.

gerardog avatar Jul 24 '23 23:07 gerardog

I like this idea.

What about something like a sqlite db? Seems like it would be more suited to a cross process read/write scenario. What do you think?

badmotorfinger avatar Jul 25 '23 10:07 badmotorfinger