Add an option to remove only consecutive history duplicates
See original GitHub issueEnvironment data
PS version: 5.1.17134.228
PSReadline version: 1.2
os: 10.0.17134.1 (WinBuild.160101.0800)
PS file version: 10.0.17134.1 (WinBuild.160101.0800)
Description
PSReadline has the option Set-PSReadlineOption -HistoryNoDuplicates
(The plain Windows console has the equivalent “Discard Old Duplicates”), this option removes all duplicate history entries, even non-consecutive ones. For example: Typing the commands echo 1
, echo 2
, echo 2
, echo 1
, the history will be echo 1
, echo 2
.
Bash has the option HISTCONTROL=ignoredups
, and Zsh has HIST_IGNORE_DUPS
. These options only remove consecutive duplicates. For example: Typing the commands echo 1
, echo 2
, echo 2
, echo 1
, the history will be echo 1
, echo 2
, echo 1
.
I think the Bash/Zsh behavior is way more intuitive and useful than removing all duplicates and it would be a great feature for PSReadline to have.
EDIT: There is also the related HISTCONTROL=ignorespace
, HIST_IGNORE_SPACE
which is also nice to have and probably quite easy to implement.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
HIST_IGNORE_SPACE is easy - you can add something like this to your profile:
This example will ignore short commands (3 or less) and commands that start with a space or semi-colon.
I thought I had this example in the sample profile but apparently not.
The reported issue has been addressed in PSReadLine (I guess it was done quite a while back). Now
HistoryNoDuplicates
only removes consecutive duplicates.