refactor(cli): doom.ps1: simplify
Also ensures envvars persist into the after-script, and are cleared at the correct time (and only once).
This commit is contained in:
parent
498966179f
commit
08abc7d698
1 changed files with 23 additions and 21 deletions
44
bin/doom.ps1
44
bin/doom.ps1
|
@ -7,32 +7,34 @@ if (!(Get-Command -Erroraction silentlycontinue emacs.exe)) {
|
||||||
|
|
||||||
$doom = "$PSScriptRoot/doom"
|
$doom = "$PSScriptRoot/doom"
|
||||||
$emacs = if ($env:EMACS) { $env:EMACS } else { (Get-Command emacs.exe).Path }
|
$emacs = if ($env:EMACS) { $env:EMACS } else { (Get-Command emacs.exe).Path }
|
||||||
$emacsargs = "-q", "--no-site-file", "--batch"
|
|
||||||
$oldemacsdir = $env:EMACSDIR
|
$oldemacsdir = $env:EMACSDIR
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$env:EMACSDIR = if (-not $env:EMACSDIR) { (get-item $PSScriptRoot).parent.FullName } else { $env:EMACSDIR }
|
if (-not $env:EMACSDIR) { $env:EMACSDIR = (get-item $PSScriptRoot).parent.FullName; }
|
||||||
$env:__DOOMSH = if (-not $env:__DOOMSH) { "ps1" } else { $env:__DOOMSH }
|
if (-not $env:__DOOMSH) { $env:__DOOMSH = "ps1"; }
|
||||||
$env:__DOOMPID = if (-not $env:__DOOMPID) { $PID } else { $env:__DOOMPID }
|
if (-not $env:__DOOMPID) { $env:__DOOMPID = $PID; }
|
||||||
$env:__DOOMSTEP = if (-not $env:__DOOMSTEP) { 0 } else { $env:__DOOMSTEP }
|
if (-not $env:__DOOMSTEP) { $env:__DOOMSTEP = 0; }
|
||||||
$cols = (Get-Host).UI.RawUI.WindowSize.Width
|
if (-not $env:__DOOMGEOM) {
|
||||||
$lines = (Get-Host).UI.RawUI.WindowSize.Height
|
$cols = (Get-Host).UI.RawUI.WindowSize.Width
|
||||||
$env:__DOOMGEOM = if (-not $env:__DOOMGEOM) { "$cols`x$lines" } else { $env:__DOOMGEOM }
|
$lines = (Get-Host).UI.RawUI.WindowSize.Height
|
||||||
|
$env:__DOOMGEOM = "$cols`x$lines"
|
||||||
|
}
|
||||||
# $env:__DOOMGPIPE = if (-not $env:__DOOMGPIPE) { $env:__DOOMPIPE } else { $env:__DOOMGPIPE }
|
# $env:__DOOMGPIPE = if (-not $env:__DOOMGPIPE) { $env:__DOOMPIPE } else { $env:__DOOMGPIPE }
|
||||||
# $env:__DOOMPIPE = ""
|
# $env:__DOOMPIPE = ""
|
||||||
|
|
||||||
& $emacs $emacsargs --load "$doom" -- --no-color $args
|
& $emacs -q --no-site-file --batch --load "$doom" -- --no-color $args
|
||||||
$exit = $LASTEXITCODE
|
if ($LASTEXITCODE -eq 254) {
|
||||||
|
& pwsh "$($env:temp)\doom.$($env:__DOOMPID).$($env:__DOOMSTEP).ps1" $PSCommandPath $args
|
||||||
|
$exit = $LASTEXITCODE
|
||||||
|
}
|
||||||
|
exit $exit
|
||||||
} finally {
|
} finally {
|
||||||
$env:EMACSDIR = $oldemacsdir
|
# Only clear the env at top-level
|
||||||
Remove-Item Env:\__DOOMSH
|
if ($env:__DOOMSTEP -eq 0) {
|
||||||
Remove-Item Env:\__DOOMPID
|
$env:EMACSDIR = $oldemacsdir
|
||||||
Remove-Item Env:\__DOOMSTEP
|
Remove-Item Env:\__DOOMSH
|
||||||
Remove-Item Env:\__DOOMGEOM
|
Remove-Item Env:\__DOOMPID
|
||||||
|
Remove-Item Env:\__DOOMSTEP
|
||||||
|
Remove-Item Env:\__DOOMGEOM
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($exit -eq 254) {
|
|
||||||
& pwsh "$($env:temp)\doom.$($env:__DOOMPID).$($env:__DOOMSTEP).ps1" $PSCommandPath $args
|
|
||||||
$exit = $LASTEXITCODE
|
|
||||||
}
|
|
||||||
exit $exit
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue