=Generalize editor initialization

This commit is contained in:
Gal Szkolnik 2021-08-10 15:50:43 +00:00
parent 0a2bb25700
commit 2ce7561fb7
1 changed files with 5 additions and 5 deletions

View File

@ -5,7 +5,7 @@
)
begin {
$global:WaitForEditor = (($WaitForEditor, 0 -ne $null)[0], 5 -ne 0)[0]
$global:WaitForEditor = (($WaitForEditor, -1 -ne $null)[0], 5 -ne -1)[0]
$PathForEditor = @()
}
process {
@ -15,7 +15,7 @@ process {
}
end {
$local:editors = $env:EDITOR,'nvim','code'
$local:editors = $env:EDITOR,'nvim','codium','code'
$local:editor = $null
foreach( $local:testEditor in $editors ) {
if( $(try{Get-Command -ListImported -Type Application $testEditor -ErrorAction SilentlyContinue}catch{}) ) {
@ -28,10 +28,10 @@ end {
$editor += ' -p'
}
if( $editor -match 'code(\.exe)?"$' ) {
if( -not (Get-Process -Name 'code' -ErrorAction SilentlyContinue) ) {
if( $EditorProcessName ) {
if( -not (Get-Process -Name $EditorProcessName -ErrorAction SilentlyContinue) ) {
Invoke-ExpressionEx -sudo:$sudo "& $editor"
while( -not (Get-Process -Name 'code' -ErrorAction SilentlyContinue) ) {
while( -not (Get-Process -Name $EditorProcessName -ErrorAction SilentlyContinue) ) {
Start-Sleep -Seconds 1
}
Write-Host -ForegroundColor DarkCyan "Please wait, initializing editor..."