Kenichi Maehashi's Blog

脳内コアダンプ

RSS
Category: Computer
setopt hist_ignore_dups & setopt hist_ignore_space for PowerShell 2.0 or later - add it to your Profile.ps1:
# History
$MaximumHistoryCount = 32767
$HistoryFile = "~/PowerShell_History.csv"
If (Test-Path $HistoryFile) {
Import-CSV $HistoryFile | Add-History
}
[void] (Register-EngineEvent -SourceIdentifier([System.Management.Automation.PsEngineEvent]::Exiting) -Action {
[Microsoft.PowerShell.Commands.HistoryInfo[]] $hist = Get-History -Count $MaximumHistoryCount
[Array]::Reverse($hist); $hist = ($hist | Select-Object -Unique); [Array]::Reverse($hist)
$hist |? {$_.CommandLine -notlike " *"} | Export-CSV $HistoryFile
})
You can search the history using "#" and the tab expansion, e.g.,
PS>#get-[tab]
will show you the candidates from your history.

Enjoy!

Update - 2009.01.22
This will be very slow if you have more than about 200 history entries. You might comment out the [Array]::Reverse... line; this disables "hist_ignore_dups" function.

Comments

Leave Yours...
Name:
E-mail / URL (optional):
Comment:
Are You Robot?: