Added better constrol over waiting for editor
This commit is contained in:
parent
187eb22b99
commit
0a2bb25700
|
@ -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
|
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'"
|
Write-Host -ForegroundColor DarkGreen "When done editing, you might want to run '. Reload-MyScripts'"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
begin {
|
begin {
|
||||||
|
$global:WaitForEditor = (($WaitForEditor, 0 -ne $null)[0], 5 -ne 0)[0]
|
||||||
$PathForEditor = @()
|
$PathForEditor = @()
|
||||||
}
|
}
|
||||||
process {
|
process {
|
||||||
|
@ -29,7 +30,15 @@ end {
|
||||||
|
|
||||||
if( $editor -match 'code(\.exe)?"$' ) {
|
if( $editor -match 'code(\.exe)?"$' ) {
|
||||||
if( -not (Get-Process -Name 'code' -ErrorAction SilentlyContinue) ) {
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue