You are not logged in.

#1 2017-10-06 08:25:47

lknix
Member
Registered: 2008-10-20
Posts: 19

ZSH history options don't work as expected

Hi,

I'm trying to keep a ZSH history with only unique commands and it's not working (my history file is full of dupes).

# From .zshrc:

export HISTFILE="$HOME/.zsh_history"
export HISTSIZE=10000
export SAVEHIST=$HISTSIZE

# Treat the '!' character specially during expansion.
setopt BANG_HIST

# Don't store ts and duration of the execution.
setopt EXTENDED_HISTORY

# Write to the history file immediately, not when the shell exits.
setopt INC_APPEND_HISTORY

# Share history between all sessions.
setopt SHARE_HISTORY

# Expire duplicate entries first when trimming history.
setopt HIST_EXPIRE_DUPS_FIRST

# Don't record an entry that was just recorded again.
setopt HIST_IGNORE_DUPS

# Delete old recorded entry if new entry is a duplicate.
setopt HIST_IGNORE_ALL_DUPS

# Do not display a line previously found.
setopt HIST_FIND_NO_DUPS

# Don't record an entry starting with a space.
setopt HIST_IGNORE_SPACE

# Don't write duplicate entries in the history file.
setopt HIST_SAVE_NO_DUPS

# Remove superfluous blanks before recording entry.
setopt HIST_REDUCE_BLANKS

# Don't execute immediately upon history expansion.
setopt HIST_VERIFY
$ setopt | grep hist
extendedhistory
histfindnodups
histignorealldups
histignoredups
histignorespace
histreduceblanks
histsavenodups
histverify
incappendhistory
sharehistory

Now the funny thing - browsing through history show duplicate commands:

$ fc -lnd -10
16:48  cat .zsh_history
16:52  unsetopt
16:52  unsetopt | grep exte
16:55  fc -lnd -100
16:57  vim .zshrc
16:59  tail -10 .zsh_history
17:01  wc -l .zsh_history
17:01  tail .zsh_history
17:01  pwd
17:01  uname
17:02  date
17:02  tail -10 .zsh_history
17:03  date
17:08  setopt
17:10  unsetopt | grep hist
17:10  setopt
17:12  ls

I thought this is because I've enabled EXTENDED_HISTORY (which stores in ": ts:duration;command" format). I've tried disabling this option by "unsetopt EXTENDED_HISTORY" but history format didn't change. Currently, I'm lost - original configuration doesn't work as expected and then even "unsetop EXTENDED_HISTORY" doesn't seem to do anything.

Maybe I'm doing something stupid and can't see it. Any ideas?

Offline

#2 2017-10-06 09:13:46

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,356

Re: ZSH history options don't work as expected

I haven't used these zsh options, but based on their descriptions I think this is expected behaviour. Your last two options basically mean 'remove dups first when clearing' and "don't record a repeated entry". That last one should mean something run multiple times in a row, not something run again which has been run 20 commands before.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#3 2017-10-06 10:23:15

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Re: ZSH history options don't work as expected

See my dot files github for a workaround I use.  It's the "h" alias.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

Board footer

Powered by FluxBB