zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Cc: Max Blue <Bluemax48@hotmail.com>
Subject: Re: About de-duplicating the history and history appending
Date: Sat, 10 Feb 2024 22:33:04 -0600	[thread overview]
Message-ID: <CAH+w=7ZNjnGOrgRgh+kJrHQGpbs+Zdh4yrxSYxmMmQsDMKUb=A@mail.gmail.com> (raw)
In-Reply-To: <ea770f18-2b5b-4d66-90bc-2949f5a646ce@app.fastmail.com>

On Sat, Feb 10, 2024 at 7:28 PM Lawrence Velázquez <larryv@zsh.org> wrote:
>
> On Sat, Feb 10, 2024, at 6:00 PM, Max Blue wrote:
> >
> > I wanted to remove all the duplicated entries after the terminal
> > closed, so it would be far easier to search and also to keep at hand
> > the command i use the most.
>
> To be clear, the goals are:
>
> - To deduplicate the entire history file every time a shell saves
>   its history.
> - To keep concurrent shells from trampling on each other's divergent
>   history entries, as is possible without APPEND_HISTORY.
[...]
> The use of ".bash_history" here is not a mistake.  OP really is
> trying to use a single history file for both bash and zsh.

These are fundamentally incompatible goals.  Bash and zsh will not
cooperate with each other for purposes of (avoiding) overlapping
writes, the timestamp formats are incompatible, and the zsh history is
stored "metafied" -- it is not a plain text file.  That also explains
this:

> > that after running this script, some special characters becomes 'weird'
> > into the *.bash_history *viewing. With weird i mean things like *#º
> > *and* #º *,which fortunately are not present in the terminal history
> > (the commands are properly shown in there).

Moving along ...

> This was adapted from <https://unix.stackexchange.com/a/78846/2803>.

I'm not going to try to work through all of that ... but I see it does
discuss the timestamp problem.

> > *setopt HIST_IGNORE_ALL_DUPS HIST_IGNORE_ALL_DUPS HIST_IGNORE_DUPS
> > HIST_SAVE_NO_DUPS HIST_FIND_NO_DUPS*

I think you mean for one of those to be HIST_EXPIRE_DUPS_FIRST ?

My approach to this would be to use "fc -p" to point to a new history
file with setopts as appropriate from the above, pull the HISTFILE
into that with "fc -R", write it out again with "fc -W", then move
that to the desired history file with appropriate locking (which you
can probably do by calling "fc -P" to switch back to the original
history and then cycling -R/-W again).

If you write that as a zsh script you can invoke it from bash to clean
up bash's history as well, with the timestamp caveat.  I'm not at my
usual computer right now so not going to test details, I'll chime in
again later if things seem to be going awry.


  reply	other threads:[~2024-02-11  4:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-10 23:00 Max Blue
2024-02-11  1:27 ` Lawrence Velázquez
2024-02-11  4:33   ` Bart Schaefer [this message]
2024-02-11  9:33     ` Max Blue

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='CAH+w=7ZNjnGOrgRgh+kJrHQGpbs+Zdh4yrxSYxmMmQsDMKUb=A@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=Bluemax48@hotmail.com \
    --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).