Skip to content

Commit 030c430

Browse files
StartAutomatingStartAutomating
authored andcommitted
fix: Improving obs-powershell startup time ( Fixes #214 )
1 parent 295f245 commit 030c430

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

obs-powershell.psm1

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
$CommandsPath = (Join-Path $PSScriptRoot "Commands")
2-
:ToIncludeFiles foreach ($file in (Get-ChildItem -Path "$CommandsPath" -Filter "*-*.ps1" -Recurse)) {
3-
if ($file.Extension -ne '.ps1') { continue } # Skip if the extension is not .ps1
4-
foreach ($exclusion in '\.[^\.]+\.ps1$') {
5-
if (-not $exclusion) { continue }
6-
if ($file.Name -match $exclusion) {
7-
continue ToIncludeFiles # Skip excluded files
8-
}
9-
}
10-
. $file.FullName
1+
param()
2+
3+
if ((-not (Test-Path '.git')) -or $args -match 'production') {
4+
. $PSScriptRoot/allcommands.ps1
5+
} else {
6+
$CommandsPath = (Join-Path $PSScriptRoot "Commands")
7+
:ToIncludeFiles foreach ($file in (Get-ChildItem -Path "$CommandsPath" -Filter "*-*.ps1" -Recurse)) {
8+
if ($file.Extension -ne '.ps1') { continue } # Skip if the extension is not .ps1
9+
foreach ($exclusion in '\.[^\.]+\.ps1$') {
10+
if (-not $exclusion) { continue }
11+
if ($file.Name -match $exclusion) {
12+
continue ToIncludeFiles # Skip excluded files
13+
}
14+
}
15+
. $file.FullName
16+
}
1117
}
1218

19+
20+
1321
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
1422
Get-OBSEffect | Stop-OBSEffect
1523
if (${obs-powershell}.Beat.Timer) {
@@ -27,6 +35,7 @@ if ($home) {
2735
New-PSDrive -Name "my-$($MyModule.Name)" -Root (Join-Path $home ".$($myModule.Name)") -Description "My $MyModule" @NewDriveSplat
2836
}
2937

38+
#region obs-powershell startup
3039
foreach ($noun in 'Streaming','Recording') {
3140
foreach ($verb in 'Start', 'Stop') {
3241
Set-Alias "$verb-$noun" "$verb-OBS$($noun -replace 'ing')"
@@ -47,4 +56,6 @@ if (Test-Path $ModuleProfilePath) {
4756
. $ModuleProfilePath
4857
}
4958

59+
#endregion obs-powershell startup
60+
5061
Export-ModuleMember -Function * -Variable $script:variablesToExport -Alias *

0 commit comments

Comments
 (0)