Added better constrol over waiting for editor

This commit is contained in:
Gal Szkolnik 2021-07-14 17:05:48 -04:00
parent 187eb22b99
commit 0a2bb25700
2 changed files with 13 additions and 4 deletions

View File

@ -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
}

View File

@ -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()
}
}
}