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)
}
}
The option is actually working more or less as expected, see issue #74 for a discussion on the current implementation.
That said, when loading history, I've considered ignoring duplicates so that you can load more items before hitting the limit. Is that your concern?
I think I also have a bug where Ctrl+r will recall duplicates but shouldn't. UpArrow will not recall duplicates though.
I see - I was looking at the history file and seeing a lot of duplicates stored, that is why I thought it did not work. But when I actually do the history search, PSReadLine does skip duplicated items. Thank you so much for your quick reply.
That said, when loading history, I've considered ignoring duplicates so that you can load more items before hitting the limit. Is that your concern?
I would prefer to have an option to not store duplicated items in the first place, but I think this would be also great - this was the reason why I was looking the history file in the first place. (I remembered I had one command in the history but PSReadLine did not find it - it was because of the limit).
@lzybkr should Set-PSReadLineOption -HistoryNoDuplicates
be a default?
Most helpful comment
@lzybkr should
Set-PSReadLineOption -HistoryNoDuplicates
be a default?