Skip to content
johnfleenor edited this page Jan 3, 2017 · 1 revision

function Copy-HistoryItem{ [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$fg = $psise.Options.OutputPaneForegroundColor $bg = $psise.Options.OutputPaneBackgroundColor $objForm = New-Object System.Windows.Forms.Form $objForm.Text = "History" $objForm.Size = New-Object System.Drawing.Size(300,300) $objForm.StartPosition = "CenterScreen" $objForm.FormBorderStyle = "SizableToolWindow"

$objForm.KeyPreview = $True $objForm.Add_KeyDown({if ($.KeyCode -eq "Enter") {$psISE.CurrentPowerShellTab.CommandPane.InsertText($objlb.Selecteditem);$objForm.Close()}}) $objForm.Add_KeyDown({if ($.KeyCode -eq "Escape") {$objForm.Close()}})

$objForm.Add_Resize({$objlb.Size = New-Object System.Drawing.Size(($objForm.width-15),$objForm.height) })

$objlb = New-Object System.Windows.Forms.ListBox $objlb.Location = New-Object System.Drawing.Size(0,0) $objlb.Size = New-Object System.Drawing.Size(($objForm.width-15),$objForm.height) $objlb.backcolor= [system.drawing.color]::fromargb($bg.a, $bg.r, $bg.g, $bg.b) $objlb.forecolor = [system.drawing.color]::fromargb($fg.a, $fg.r, $fg.g, $fg.b) $objlb.Add_DoubleClick({$psISE.CurrentPowerShellTab.CommandPane.InsertText($objlb.Selecteditem);$objForm.Close()}) $objForm.Controls.Add($objlb)

get-history | foreach {$objlb.items.add($_.commandline)} | out-null

$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()}) [void] $objForm.ShowDialog() } $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add(‘Show history’,{Copy-HistoryItem},"F7")

Clone this wiki locally