-
-
Save dseeni/9bf27894cfaa9feaf9ea65e60f1db2bb to your computer and use it in GitHub Desktop.
lazy load in powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $LazyLoadProfile = [PowerShell]::Create() | |
| [void]$LazyLoadProfile.AddScript(@' | |
| Import-Module posh-git | |
| '@) | |
| $LazyLoadProfileRunspace = [RunspaceFactory]::CreateRunspace() | |
| $LazyLoadProfile.Runspace = $LazyLoadProfileRunspace | |
| $LazyLoadProfileRunspace.Open() | |
| [void]$LazyLoadProfile.BeginInvoke() | |
| $null = Register-ObjectEvent -InputObject $LazyLoadProfile -EventName InvocationStateChanged -Action { | |
| Import-Module -Name posh-git | |
| $global:GitPromptSettings.DefaultPromptPrefix.Text = 'PS ' | |
| $global:GitPromptSettings.DefaultPromptBeforeSuffix.Text = '`n' | |
| $LazyLoadProfile.Dispose() | |
| $LazyLoadProfileRunspace.Close() | |
| $LazyLoadProfileRunspace.Dispose() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment