Skip to content

Instantly share code, notes, and snippets.

@hyrious
Created February 14, 2021 07:19
Show Gist options
  • Save hyrious/65c85889e18e916fe0a170f919afb5c1 to your computer and use it in GitHub Desktop.
Save hyrious/65c85889e18e916fe0a170f919afb5c1 to your computer and use it in GitHub Desktop.
lazy load in powershell
$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