Eliminate duplicates in command history

Posted by godefroi on Mon 16 Aug 2004 07:11 PM — 9 posts, 32,888 views.

#0
Similar to the "Discard Old Duplicates" option for the command prompt in Windows, or the HISTCONTROL=ignoredups option for the bash shell in *nix.

Basically, it means that if a command is already in the command history, it removes it before adding it again so you don't get duplicates. If you entered commands such as the following:

a
b
b
a
c
d

Currently you'd get d,c,a,b,a in your command history. If you enabled this option you should get d,c,a,b in your history.
USA #1
But that would break any scripts that send the "last command" from the history. History is what youve sent, in order. What would the purpose of an option such as this?
Greece #2
No, he means remove it from history before adding it. Such an option would be useful and would reduce the time it takes to browse the history... Can it be easily implemented?
USA #3
Such a feature would be good only if it were optional, not permanent.
Greece #4
I agree, it has to be an option.
Australia Forum Administrator #5
A command history that doesn't have duplicates? Sounds like getting a book and reducing its size by eliminating all the duplicated words (eg. the word "the" seems to occur an awful lot, is it really necessary?).

Seriously, I suppose it could be done. You could also write a script that scans the command history and makes a list of unique entries, if that is what you want, for some reason.
#6
For example,

cast a
cast b
cast c
cast a
cast b
cast a
cast b
cast a
cast b

now, if I want to cast c again, I have to go up through b,a,b,a,b,a to c.

If elim dupes were on, I would go through b,a to c.

The logic change is simply to remove all "x" from the command history before adding "x" at the end

The command prompt in windows has the option, as does bash in *nix. Someone thought it was useful.
Amended on Thu 19 Aug 2004 11:16 PM by godefroi
Greece #7
It makes no sense for the command history to have duplicates, because it's there to help you type faster, not provide you with the entire history of what you had typed, I think. Such an option would help you find what you want faster.
Australia Forum Administrator #8
Added as suggestion #527.