Fzf: Remove duplicates?

Created on 30 May 2014  路  7Comments  路  Source: junegunn/fzf

Command history contains plenty of duplicates usually, and these are just noise. Would be nice to have them removed from the list.

question wontfix

Most helpful comment

Ah, now I get it. ignoredups prevents cluttering history with runs of the same command, but keeps invocations interleaved with other commands, so that the history reads sensibly. I often copy and edit history to document what I did, so this is helpful (and holes in history caused by deleting previous invocations would be harmful).

I would argue that it does not make sense for fzf to go and gather identical commands sprinkled here and there in the history, because it doesn't show you command context (next/previous commands). It should either show only the most recent match, or at least collapse runs of identical matches.

All 7 comments

On bash, I can prevent duplicates in the history by setting HISTCONTROL as follows:

export HISTCONTROL=ignoreboth:erasedups

For zsh the equivalent seems to be HIST_IGNORE_ALL_DUPS:
See http://zsh.sourceforge.net/Doc/Release/Options.html

I have ignoredups in my .bashrc, why is erasedups necessary in addition?

Even after that it won't be perfect, at least in old bash 3.x. People make elaborate PSCMD to deal with it, or just live with it :)

Ah, now I get it. ignoredups prevents cluttering history with runs of the same command, but keeps invocations interleaved with other commands, so that the history reads sensibly. I often copy and edit history to document what I did, so this is helpful (and holes in history caused by deleting previous invocations would be harmful).

I would argue that it does not make sense for fzf to go and gather identical commands sprinkled here and there in the history, because it doesn't show you command context (next/previous commands). It should either show only the most recent match, or at least collapse runs of identical matches.

Yeah, I agree. The decision should be up to the individual user.

And for your information, the default CTRL-R key binding uses +s (or --no-sort) option to keep the order of commands intact and the recent version of fzf allows you to scroll through the result beyond the scope of the screen, so it's pretty nice to browse the history with it.

I'm closing this issue.

I found that bash wasn't removing duplicates very well trying these options, so I made a quick python script to deduplicate history when the bash session ends:

https://github.com/naggie/dotfiles/blob/fzf/bin/cleanup-history.py

Instructions are at the top of the file.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skamsie picture skamsie  路  3Comments

sassanh picture sassanh  路  3Comments

ahmedelgabri picture ahmedelgabri  路  3Comments

leonklingele picture leonklingele  路  3Comments

jan-warchol picture jan-warchol  路  3Comments