function Get-HistoryEntries { <# .SYNOPSIS Get the history according to what was saved by PSReadLine #> [CmdletBinding()] [OutputType([System.Collections.ArrayList])] param ( [switch]$SkipMultilines, [switch]$OnlyMultilines, [switch]$SkipLongLines, [Parameter()] [string[]]$AdditionalPath ) $logLead = Get-LogLeadName $longLineLength = 120 # 120 characters is a pretty long line if ($SkipMultilines -and $OnlyMultilines) { throw "$logLead : You can't specify both skip and only multilines" } try { $path = (Get-PSReadlineOption).HistorySavePath } catch { Write-Warning "$logLead : Is PSReadLine installed? Can't find the history save path" return } $lines = @() foreach ($filePath in $AdditionalPath) { $lines += Get-Content -Path $filePath } $lines += Get-Content -Path $path $records = New-Object -TypeName "System.Collections.ArrayList" $isMultiline = $false $groupedLines = @() foreach ($line in $lines) { if ($line.EndsWith('`')) { $line = $line.TrimEnd('`') $groupedLines += $line $isMultiline = $true continue } $groupedLines += $line $lineIsLong = ($groupedLines -join '').Length -gt $longLineLength $skipAdd = ($SkipLongLines -and $lineIsLong) -or ($OnlyMultilines -and !$isMultiline) -or ($SkipMultilines -and $isMultiline) if (!$skipAdd) { $records.Add($groupedLines) | Out-Null } $groupedLines = @() $isMultiline = $false } return $records }