question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add an option to remove only consecutive history duplicates

See original GitHub issue

Environment 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
lzybkrcommented, Aug 25, 2018

HIST_IGNORE_SPACE is easy - you can add something like this to your profile:

Set-PSReadLineOption -AddToHistoryHandler {
    param([string]$line)
    return $line.Length -gt 3 -and $line[0] -ne ' ' -and $line[0] -ne ';'
}

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.

1reaction
daxian-dbwcommented, Oct 27, 2021

For example: Typing the commands echo 1, echo 2, echo 2, echo 1, the history will be echo 1, echo 2.

The reported issue has been addressed in PSReadLine (I guess it was done quite a while back). Now HistoryNoDuplicates only removes consecutive duplicates.

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add an option to remove only consecutive history duplicates
Bash has the option HISTCONTROL=ignoredups , and Zsh has HIST_IGNORE_DUPS . These options only remove consecutive duplicates. For example: ...
Read more >
How can I remove duplicates in my .bash_history ...
I needed a way to merge my memory and disk history when my shell session exits, (from multiple terminals), or just merge histories...
Read more >
Remove all consecutive duplicates from the string
Given a string S, The task is to remove all the consecutive duplicate characters of the string and return the resultant string.
Read more >
bash - Can I remove all duplicates (not only consecutive) to ...
So far I have the following under git: My editor (Emacs/Spacemacs) configuration. My bash configuration; Various todo lists.
Read more >
How to avoid duplicate entries in .bash_history
From the bash man page: HISTCONTROL. A colon-separated list of values controlling how commands are saved on the history list.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found