Skip to content

Commit

Permalink
This[1] blog post describes a faster method of importing use script into
Browse files Browse the repository at this point in the history
the powershell session by loading the file contents into memory proir to
letting powershell parse them for auto-complete values.

Reference:

1: https://becomelotr.wordpress.com/2017/02/13/expensive-dot-sourcing/

Testing:

Test cmderdev#1
---
dotsource(ms) | scriptblock(ms) | filename(test data)
---
  18  |  13  | Approve-Script.ps1
   6  |   2  | Clear-PrinterQueue.ps1
  14  |   3  | ConvertTo-ImageFormat.ps1
   9  |   2  | Copy-MultipleItems.ps1
   6  |   2  | Enter-RemoteSession.ps1
   6  |   3  | Get-CurrentUser.ps1
   7  |   3  | Get-LogonHistory.ps1
   6  |   2  | Get-SSID.ps1
   6  |   2  | Invoke-DscPullAndApply.ps1
   8  |   3  | Move-Drive.ps1
   7  |   2  | New-ComputerList.ps1
   6  |   2  | New-Directory.ps1
   6  |   3  | Set-Proxy.ps1
   7  |   2  | Shortcut.ps1
   6  |   3  | Start-Delprof.ps1
   6  |   3  | Suspend-Computer.ps1
   9  |   4  | SystemInformation.ps1
   6  |   3  | Test-ModuleSpeed.ps1
   7  |   5  | Test-TCPConnection.ps1
   6  |   2  | Update-ModuleReadMe.ps1
  11  |   3  | Watch-Here.ps1

Test cmderdev#2
---
dotsource(ms) | scriptblock(ms) | filename(test data)
---
  40  |  24  |  Approve-Script.ps1
   8  |   4  |  Clear-PrinterQueue.ps1
  24  |  12  |  ConvertTo-ImageFormat.ps1
  14  |   8  |  Copy-MultipleItems.ps1
   7  |   4  |  Enter-RemoteSession.ps1
  10  |   4  |  Get-CurrentUser.ps1
  30  |   6  |  Get-LogonHistory.ps1
   6  |   4  |  Get-SSID.ps1
   7  |   4  |  Invoke-DscPullAndApply.ps1
  11  |   8  |  Move-Drive.ps1
  11  |   5  |  New-ComputerList.ps1
  11  |   4  |  New-Directory.ps1
   6  |   5  |  Set-Proxy.ps1
  11  |   5  |  Shortcut.ps1
  10  |  12  |  Start-Delprof.ps1
  12  |   5  |  Suspend-Computer.ps1
  69  |   5  |  SystemInformation.ps1
  11  |   4  |  Test-ModuleSpeed.ps1
   6  |   7  |  Test-TCPConnection.ps1
   8  |   4  |  Update-ModuleReadMe.ps1
  10  |   9  |  Watch-Here.ps1
  • Loading branch information
Jackbennett committed Feb 15, 2017
1 parent 2bb5ce0 commit eec4221
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions vendor/profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ if (-not (test-path "$ENV:CMDER_ROOT\config\profile.d")) {
mkdir "$ENV:CMDER_ROOT\config\profile.d"
}

pushd $ENV:CMDER_ROOT\config\profile.d
foreach ($x in ls *.ps1) {
# write-host write-host Sourcing $x
. $x
foreach ($file in (Get-ChildItem "$($env:CMDER_ROOT)\config\profile.d" -Filter '*.ps1') ) {
# Grab the contents of files at once and parse that as a script block.
# faster script loading, see: https://becomelotr.wordpress.com/2017/02/13/expensive-dot-sourcing/
. (
[scriptblock]::Create(
[io.file]::ReadAllText($file.fullname)
)
)
}
popd

#
# Prompt Section
Expand Down

0 comments on commit eec4221

Please sign in to comment.