Windows PowerShell Persistent History -
so found excellent looking method of persisting history in windows powershell.
# persistent history # save last 200 history items on exit $maximumhistorycount = 200 $historypath = join-path (split-path $profile) history.clixml # hook powershell's exiting event & hide registration -supportevent (from nivot.org) register-engineevent -sourceidentifier powershell.exiting -supportevent -action { get-history -count $maximumhistorycount | export-clixml (join-path (split-path $profile) history.clixml) } # load previous history, if exists if ((test-path $historypath)) { import-clixml $historypath | ? {$count++;$true} | add-history write-host -fore green "`nloaded $count history item(s).`n" } # aliases , functions make useful new-alias -name -value invoke-history -description "invoke history alias" rename-item alias:\h original_h -force function h { get-history -c $maximumhistorycount } function hg($arg) { get-history -c $maximumhistorycount | out-string -stream | select-string $arg }
however when paste $profile , restart powershell following error
register-engineevent : missing argument parameter 'action'. specify parameter of type 'system.management.automation.scriptblock' , try again. @ d:\path\to\windowspowershell\microsoft.powershell_profile.ps1:20 char:73 + register-engineevent -sourceidentifier powershell.exiting -supportevent -action + ~~~~~~~ + categoryinfo : invalidargument: (:) [register-engineevent], parameterbindingexception + fullyqualifiederrorid : missingargument,microsoft.powershell.commands.registerengineeventcommand
very related question "how access history using up/down arrows?" psreadline module solves this:
install-package psreadline
then add:
import-module psreadline
to $profile
.
Comments
Post a Comment