Skip to content

Instantly share code, notes, and snippets.

@dseeni
Forked from hyrious/lazy-load-pwsh-module.ps1
Created March 10, 2023 20:24
Show Gist options
  • Select an option

  • Save dseeni/9bf27894cfaa9feaf9ea65e60f1db2bb to your computer and use it in GitHub Desktop.

Select an option

Save dseeni/9bf27894cfaa9feaf9ea65e60f1db2bb 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