Created
February 14, 2021 07:19
-
-
Save hyrious/65c85889e18e916fe0a170f919afb5c1 to your computer and use it in GitHub Desktop.
lazy load in powershell
This file contains 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