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.

-HistoryNoDuplicates does not have any effect

See original GitHub issue

I have Set-PSReadLineOption -HistoryNoDuplicates in my profile file, and Get-PSReadlineOption shows HistoryNoDuplicates : True. But duplicated entries are being added to the ConsoleHost_history.txt file. I’m using version 1.0.0.13. The following is all the options I have for PSReadLine:

Import-Module PSReadLine

Set-PSReadLineOption -HistoryNoDuplicates 
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineOption -HistorySaveStyle SaveIncrementally
Set-PSReadLineOption -MaximumHistoryCount 4000
# history substring search
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

# Tab completion
Set-PSReadlineKeyHandler -Chord 'Shift+Tab' -Function Complete
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

# automatic quotation
Set-PSReadlineKeyHandler -Chord 'Oem7','Shift+Oem7' `
                         -BriefDescription SmartInsertQuote `
                         -LongDescription "Insert paired quotes if not already on a quote" `
                         -ScriptBlock {
    param($key, $arg)

    $line = $null
    $cursor = $null
    [PSConsoleUtilities.PSConsoleReadline]::GetBufferState([ref]$line, [ref]$cursor)

    if ($line[$cursor] -eq $key.KeyChar) {
        # Just move the cursor
        [PSConsoleUtilities.PSConsoleReadline]::SetCursorPosition($cursor + 1)
    }
    else {
        # Insert matching quotes, move cursor to be in between the quotes
        [PSConsoleUtilities.PSConsoleReadline]::Insert("$($key.KeyChar)" * 2)
        [PSConsoleUtilities.PSConsoleReadline]::GetBufferState([ref]$line, [ref]$cursor)
        [PSConsoleUtilities.PSConsoleReadline]::SetCursorPosition($cursor - 1)
    }
}

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
vorscommented, May 17, 2016

@lzybkr should Set-PSReadLineOption -HistoryNoDuplicates be a default?

2reactions
lzybkrcommented, Apr 12, 2022

Shared history relies on the file size to know when to reread history. Trimming history would break that, so another mechanism would be needed to notify other sessions that new history was added.

This would actually be a good thing to add - I just never got around to it.

If I spend any time on history, I’m more likely to replace the simple text file with a sqlite database and would design the schema so duplicates are impossible to add.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set-PSReadLineOption (PSReadLine) - PowerShell
The scriptblock returns $false if the command started with git . This has the same effect as returning the SkipAdding AddToHistory enum. If...
Read more >
Powershell history isn't persistent anymore
As noted in my question, as a workaround I currently use Import-Module PSReadLine in my profile file, which I access via notepad $PROFILE...
Read more >
windows 10 - How to remove command duplicates?
I tried to check the Discard Old Duplicates box in Properties/Options, but this did not work. How do I turn off duplicate commands?...
Read more >
How to change colors of text and background in ...
A full sequence to set both foreground and background using RGB syntax would be something like @{ "Selection" = "$([char]0x1b)[48;2;255;0;0m$([ ...
Read more >
Why do I have duplicates in my zsh history?
It is ignoring them if they are one after the other like histignoredups but AFAIK, my configuration should ignore any and all. >...
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