4

When enabling hist_ignore_dups in zsh, I find there are many duplicate lines in $HISTFILE.

(Note: HISTFILE="$HOME/.zsh_history")

$ cat $HISTFILE

: 1593874281:0;ls
: 1593874287:0;l
: 1593874288:0;ls
: 1593874291:0;l

I think hist_ignore_dups should solve this. (HIST_IGNORE_DUPS http://zsh.sourceforge.net/Doc/Release/Options.html).

But duplicate lines still appeared in $HISTFILE, even though hist_ignore_dups is already enabled by ohmyzsh with history plugin.

## History command configuration
setopt extended_history       # record timestamp of command in HISTFILE
setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
setopt hist_ignore_dups       # ignore duplicated commands history list
setopt hist_ignore_space      # ignore commands that start with space
setopt hist_verify            # show command with history expansion to user before running it
setopt share_history          # share command history data

I suspect that extended_history and hist_ignore_dups are in conflict.

4

As per the documentation:

HIST_IGNORE_DUPS (-h)

Do not enter command lines into the history list if they are duplicates of the previous event.

Note that it's "the" previous event and not "any" previous event.

If you want to ignore all dups, you will need to set…

drum roll

You guessed it: HIST_IGNORE_ALL_DUPS

From the documentation:

HIST_IGNORE_ALL_DUPS

If a new command line being added to the history list duplicates an older one, the older command is removed from the list (even if it is not the previous event).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.