diff --git a/base/Edit-MyScript.ps1 b/base/Edit-MyScript.ps1 index 43f7917..2f23580 100644 --- a/base/Edit-MyScript.ps1 +++ b/base/Edit-MyScript.ps1 @@ -126,11 +126,11 @@ foreach( $local:p in $ScriptPaths ) { } } -$local:sw = [System.Diagnostics.Stopwatch]::StartNew(); +$local:EditorWaitStopWatch = [System.Diagnostics.Stopwatch]::StartNew(); Edit-TextFile -Path $ScriptPaths -$sw.Stop(); +$EditorWaitStopWatch.Stop(); -if( $sw.Elapsed.TotalSeconds -lt 3 ) { +if( $EditorWaitStopWatch.Elapsed.TotalSeconds -lt $WaitForEditor ) { Write-Host -ForegroundColor DarkGreen "When done editing, you might want to run '. Reload-MyScripts'" return } diff --git a/base/Edit-TextFile.ps1 b/base/Edit-TextFile.ps1 index 4181a5c..234a27e 100644 --- a/base/Edit-TextFile.ps1 +++ b/base/Edit-TextFile.ps1 @@ -5,6 +5,7 @@ ) begin { + $global:WaitForEditor = (($WaitForEditor, 0 -ne $null)[0], 5 -ne 0)[0] $PathForEditor = @() } process { @@ -29,7 +30,15 @@ end { if( $editor -match 'code(\.exe)?"$' ) { if( -not (Get-Process -Name 'code' -ErrorAction SilentlyContinue) ) { - Invoke-ExpressionEx -sudo:$sudo $editor + Invoke-ExpressionEx -sudo:$sudo "& $editor" + while( -not (Get-Process -Name 'code' -ErrorAction SilentlyContinue) ) { + Start-Sleep -Seconds 1 + } + Write-Host -ForegroundColor DarkCyan "Please wait, initializing editor..." + Start-Sleep -Seconds $WaitForEditor + if( Test-Path variable:EditorWaitStopWatch ) { + $EditorWaitStopWatch.Restart() + } } }