zsh-users
 help / color / mirror / code / Atom feed
From: "Lawrence Velázquez" <larryv@zsh.org>
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 20:27:04 -0500	[thread overview]
Message-ID: <ea770f18-2b5b-4d66-90bc-2949f5a646ce@app.fastmail.com> (raw)
In-Reply-To: <SCYPR80MB7048BF2A0B85E587D458BBD6A94A2@SCYPR80MB7048.lamprd80.prod.outlook.com>

I participated in the aforementioned IRC discussion.  Here is some
additional information for anyone inclined to chime in:


On Sat, Feb 10, 2024, at 6:00 PM, Max Blue wrote:
> Hello.
>
> I have been trying to mix the features which allows me to de-duplicate 
> and avoid excessive lines in my history, with the 'appendhistory' 
> variable, which somehow seems to be incompatible.
>
>
>
> 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.


> After a lot of help from the people in #zsh , i encountered a way to do 
> this, 'externally', with a script.
>
>
>
> In my .zshrc i have added a 'trap my_script.sh EXIT' trap, which makes 
> the script to be ran after i close the terminal.
>
>
>
> The script in question has the following inside:
>
> ----
>
> *#!/usr/bin/env bash
>
> #tac ~/.bash_history | awk '!x[$0]++' | tac  > .bash_h && mv .bash_h 
> .bash_history *-->* *This one saves the last occurence of the repeated 
> lines(commented)*
>
> awk '!x[$0]++' ~/.bash_history > .bash_h && mv .bash_h .bash_history    
> * -->* *this is what i am using at the moment.
>
> ----

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


> So, with the default values for *share_history *and *appendhistory, 
> *and the following line also inside .zshrc:
>
> *setopt HIST_IGNORE_ALL_DUPS HIST_IGNORE_ALL_DUPS HIST_IGNORE_DUPS 
> HIST_SAVE_NO_DUPS HIST_FIND_NO_DUPS*
>
> I have it working.
>
> But an user of the #zsh channel told me that this kind of script would 
> break multi-line lines saved in the history, and i also have noticed 
> 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).

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.


> Is there some way to improve this? to make it to not break multi-line 
> history entries, to remove the 'weird characters' from the text file 
> and also to know if this would break my history in a random moment.
>
>
>
> This is my first message in here so i do not know if the order of 
> exposing it was the correct.
>
>
>
> Bluey


-- 
vq


  reply	other threads:[~2024-02-11  1:28 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 [this message]
2024-02-11  4:33   ` Bart Schaefer
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=ea770f18-2b5b-4d66-90bc-2949f5a646ce@app.fastmail.com \
    --to=larryv@zsh.org \
    --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).