mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-03 12:27:26 -05:00
fix(lib): doom/reload: on Windows
- cmd.exe chokes on the space in "C:\Program Files\...", but more importantly, doom.ps1 should be invoked with powershell, not cmd.exe. - Windows has pwsh.exe and powershell.exe, which, while not identical, are close enough for our purposes, but needed to be accounted for. Fix: #8098
This commit is contained in:
18
bin/doom.ps1
18
bin/doom.ps1
@ -1,12 +1,19 @@
|
|||||||
# bin/doom.ps1
|
# bin/doom.ps1
|
||||||
|
# TODO: Use magic shebang (polyglot)?
|
||||||
|
|
||||||
if (!(Get-Command -Erroraction silentlycontinue emacs.exe)) {
|
function Executable-Find {
|
||||||
echo "Couldn't find emacs.exe in your PATH."
|
foreach ($exe in $args) {
|
||||||
exit 1
|
if ($exe) {
|
||||||
|
$path = Get-Command $exe -ErrorAction SilentlyContinue
|
||||||
|
if ($path) { return $path.Path; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw "Could not find in $PATH: $($args -join ', ')"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$emacs = if ($env:EMACS) { $env:EMACS } else { Executable-Find "emacs.exe" }
|
||||||
|
$pwsh = Executable-Find "pwsh.exe" "powershell.exe"
|
||||||
$doom = "$PSScriptRoot/doom"
|
$doom = "$PSScriptRoot/doom"
|
||||||
$emacs = if ($env:EMACS) { $env:EMACS } else { (Get-Command emacs.exe).Path }
|
|
||||||
$oldemacsdir = $env:EMACSDIR
|
$oldemacsdir = $env:EMACSDIR
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -24,7 +31,8 @@ try {
|
|||||||
|
|
||||||
& $emacs -q --no-site-file --batch --load "$doom" -- --no-color $args
|
& $emacs -q --no-site-file --batch --load "$doom" -- --no-color $args
|
||||||
if ($LASTEXITCODE -eq 254) {
|
if ($LASTEXITCODE -eq 254) {
|
||||||
& pwsh "$($env:temp)\doom.$($env:__DOOMPID).$($env:__DOOMSTEP).ps1" $PSCommandPath $args
|
# TODO: Use Invoke-Command instead?
|
||||||
|
& $pwsh "$($env:temp)\doom.$($env:__DOOMPID).$($env:__DOOMSTEP).ps1" $PSCommandPath $args
|
||||||
$exit = $LASTEXITCODE
|
$exit = $LASTEXITCODE
|
||||||
}
|
}
|
||||||
exit $exit
|
exit $exit
|
||||||
|
@ -28,26 +28,30 @@
|
|||||||
|
|
||||||
(defmacro doom--if-compile (command on-success &optional on-failure)
|
(defmacro doom--if-compile (command on-success &optional on-failure)
|
||||||
(declare (indent 2))
|
(declare (indent 2))
|
||||||
`(let* ((doom-bin "doom")
|
`(let* ((default-directory doom-emacs-dir)
|
||||||
(doom-bin-dir (expand-file-name "bin/" doom-emacs-dir))
|
(doom-bin "doom")
|
||||||
(default-directory doom-emacs-dir)
|
(doom-bin-dir (expand-file-name "bin/"))
|
||||||
(exec-path (cons doom-bin-dir exec-path)))
|
(emacs-bin (doom-path invocation-directory invocation-name))
|
||||||
|
(exec-path (cons doom-bin-dir exec-path))
|
||||||
|
(shell-file-name shell-file-name))
|
||||||
(when (and (featurep :system 'windows)
|
(when (and (featurep :system 'windows)
|
||||||
(string-match-p "cmdproxy.exe$" shell-file-name))
|
(string-match-p "cmdproxy.exe$" shell-file-name))
|
||||||
(unless (executable-find "pwsh")
|
(if-let* ((pwsh (or (executable-find "pwsh")
|
||||||
(user-error "Powershell 3.0+ is required, but pwsh.exe was not found in your $PATH"))
|
(executable-find "powershell"))))
|
||||||
(setq doom-bin "doom.ps1"))
|
(setq doom-bin "doom.ps1"
|
||||||
;; Ensure the bin/doom operates with the same environment as this
|
shell-file-name pwsh)
|
||||||
;; running session.
|
(user-error "Powershell 3.0+ is required for `doom/reload', but no pwsh.exe or powershell.exe found in your $PATH")))
|
||||||
|
;; Ensure the bin/doom operates with the same environment as this running
|
||||||
|
;; session.
|
||||||
|
(with-current-buffer
|
||||||
(with-environment-variables
|
(with-environment-variables
|
||||||
(("PATH" (string-join exec-path path-separator))
|
(("PATH" (string-join exec-path path-separator))
|
||||||
("EMACS" (doom-path invocation-directory invocation-name))
|
("EMACS" emacs-bin)
|
||||||
("EMACSDIR" doom-emacs-dir)
|
("EMACSDIR" doom-emacs-dir)
|
||||||
("DOOMDIR" doom-user-dir)
|
("DOOMDIR" doom-user-dir)
|
||||||
("DOOMLOCALDIR" doom-local-dir)
|
("DOOMLOCALDIR" doom-local-dir)
|
||||||
("DEBUG" (if doom-debug-mode (number-to-string doom-log-level))))
|
("DEBUG" (if doom-debug-mode (number-to-string doom-log-level))))
|
||||||
(with-current-buffer
|
(compile (format ,command (file-name-concat "bin" doom-bin)) t))
|
||||||
(compile (format ,command (expand-file-name doom-bin doom-bin-dir)) t)
|
|
||||||
(let ((w (get-buffer-window (current-buffer))))
|
(let ((w (get-buffer-window (current-buffer))))
|
||||||
(select-window w)
|
(select-window w)
|
||||||
(add-hook
|
(add-hook
|
||||||
@ -58,7 +62,7 @@
|
|||||||
(delete-window w)
|
(delete-window w)
|
||||||
,on-success)
|
,on-success)
|
||||||
,on-failure))
|
,on-failure))
|
||||||
nil 'local))))))
|
nil 'local)))))
|
||||||
|
|
||||||
(defvar doom-reload-command
|
(defvar doom-reload-command
|
||||||
(format "%s sync -B -e"
|
(format "%s sync -B -e"
|
||||||
|
Reference in New Issue
Block a user