Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes duplicates from global history. Shows 'when'. #12

Merged
merged 11 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: GitVersion
id: gitversion
uses: PoshCode/Actions/gitversion@v1

- name: Install-RequiredModules
uses: PoshCode/Actions/install-requiredmodules@v1

Expand All @@ -29,7 +25,6 @@ jobs:
uses: PoshCode/actions/build-module@v1
with:
path: ${{github.workspace}}/Source
version: ${{ steps.gitversion.outputs.LegacySemVerPadded }}
destination: ${{github.workspace}}/output

- name: Upload Build Output
Expand Down
22 changes: 13 additions & 9 deletions Source/Public/f7_history.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
################################################################################
#
# f7_history -Global $true | $false
#
function f7_history {
Expand All @@ -14,6 +15,7 @@ function f7_history {

if ($global) {
# Global history
Write-Progress -Activity "Getting global (PSReadLine) command history" -PercentComplete -1
$historyItems = [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems()
[array]::Reverse($historyItems)

Expand All @@ -25,14 +27,16 @@ function f7_history {
return $true
}
return $false
} | ForEach-Object {
$startTime = if ($_.StartTime -ne $null -and $_.StartTime -ne [datetime]::MinValue) { $_.StartTime.ToLocalTime() } else { $null }
} | ForEach-Object {
$startTime = if ($null -ne $_.StartTime -and $_.StartTime -ne [datetime]::MinValue) { $_.StartTime.ToLocalTime() } else { $null }
[PSCustomObject]@{ 'CommandLine' = $_.CommandLine; 'When' = $startTime }
}
}

Write-Progress -Completed -Activity "Getting global (PSReadLine) command history"

if ($historyItems -eq $null -or $historyItems.Count -eq 0) {
Write-Host "The global (PSReadLine) history is empty."
return
if ($null -eq $historyItems -or $historyItems.Count -eq 0) {
Write-Information "The global (PSReadLine) history is empty." -InformationAction Continue
return
}

$selection = $history | Out-ConsoleGridView -OutputMode Single -Filter $line -Title "Command History for All Powershell Instances"
Expand All @@ -42,9 +46,9 @@ function f7_history {
# Local history
$history = Get-History | Sort-Object -Descending -Property Id | Select-Object @{Name = 'CommandLine'; Expression = { $_.CommandLine } } -Unique

if ($history -eq $null -or $history.Count -eq 0) {
Write-Host "The PowerShell history is empty."
return
if ($null -eq $history -or $history.Count -eq 0) {
Write-Information "The PowerShell history is empty." -InformationAction Continue
return
}

$selection = $history | Out-ConsoleGridView -OutputMode Single -Filter $line -Title "Command History"
Expand Down