fix(cli): envvar injection into bin/doom post-script
This commit is contained in:
parent
61dc1da645
commit
4c7aec35ba
1 changed files with 42 additions and 43 deletions
|
@ -1128,13 +1128,20 @@ Emacs' batch library lacks an implementation of the exec system call."
|
||||||
(persistent-files
|
(persistent-files
|
||||||
(combine-and-quote-strings (delq nil (list script-file context-file))))
|
(combine-and-quote-strings (delq nil (list script-file context-file))))
|
||||||
(persisted-env
|
(persisted-env
|
||||||
(save-match-data
|
(cl-remove-if-not
|
||||||
(cl-loop with initial-env = (get 'process-environment 'initial-value)
|
#'cdr (append
|
||||||
for env in (seq-difference process-environment initial-env)
|
`(("DOOMPROFILE" . ,(ignore-errors (doom-profile->id doom-profile)))
|
||||||
if (string-match "^\\([a-zA-Z0-9_][^=]+\\)=\\(.+\\)$" env)
|
("EMACSDIR" . ,doom-emacs-dir)
|
||||||
collect (format "%s=%s"
|
("DOOMDIR" . ,doom-user-dir)
|
||||||
(match-string 1 env)
|
("DEBUG" . ,(if init-file-debug "1"))
|
||||||
(shell-quote-argument (match-string 2 env)))))))
|
("__DOOMPID" . ,(number-to-string (doom-cli-context-pid context)))
|
||||||
|
("__DOOMSTEP" . ,(number-to-string (doom-cli-context-step context)))
|
||||||
|
("__DOOMCONTEXT" . ,context-file))
|
||||||
|
(save-match-data
|
||||||
|
(cl-loop with initial-env = (get 'process-environment 'initial-value)
|
||||||
|
for env in (seq-difference process-environment initial-env)
|
||||||
|
if (string-match "^\\([a-zA-Z0-9_][^=]+\\)=\\(.+\\)$" env)
|
||||||
|
collect (cons (match-string 1 env) (match-string 2 env))))))))
|
||||||
(cl-incf (doom-cli-context-step context))
|
(cl-incf (doom-cli-context-step context))
|
||||||
(with-file-modes #o600
|
(with-file-modes #o600
|
||||||
(doom-log "restart: writing context to %s" context-file)
|
(doom-log "restart: writing context to %s" context-file)
|
||||||
|
@ -1156,42 +1163,34 @@ Emacs' batch library lacks an implementation of the exec system call."
|
||||||
(doom-log "restart: writing post-script to %s" script-file)
|
(doom-log "restart: writing post-script to %s" script-file)
|
||||||
(doom-file-write
|
(doom-file-write
|
||||||
script-file
|
script-file
|
||||||
(let ((envvars `(("DOOMPROFILE" . ,(ignore-errors (doom-profile->id doom-profile)))
|
(pcase-exhaustive shtype
|
||||||
("EMACSDIR" . ,doom-emacs-dir)
|
("sh" `(,(if (featurep :system 'android)
|
||||||
("DOOMDIR" . ,doom-user-dir)
|
"#!/bin/sh\n"
|
||||||
("DEBUG" . ,(if init-file-debug "1"))
|
"#!/usr/bin/env sh\n")
|
||||||
("__DOOMPID" . ,(number-to-string (doom-cli-context-pid context)))
|
"trap _doomcleanup EXIT\n"
|
||||||
("__DOOMSTEP" . ,(number-to-string (doom-cli-context-step context)))
|
"_doomcleanup() {\n rm -f " ,persistent-files "\n}\n"
|
||||||
("__DOOMGEOM" . ,(number-to-string (doom-cli-context-step context)))
|
"_doomrun() {\n " ,command "\n}\n"
|
||||||
("__DOOMCONTEXT" . ,context-file))))
|
,(cl-loop for (var . val) in persisted-env
|
||||||
(pcase-exhaustive shtype
|
concat (format "%s=%s \\\n" var (shell-quote-argument val)))
|
||||||
("sh" `(,(if (featurep :system 'android)
|
,(format "PATH=\"%s%s$PATH\" \\\n"
|
||||||
"#!/bin/sh\n"
|
(doom-path doom-emacs-dir "bin")
|
||||||
"#!/usr/bin/env sh\n")
|
path-separator)
|
||||||
"trap _doomcleanup EXIT\n"
|
"_doomrun \"$@\"\n"))
|
||||||
"_doomcleanup() {\n rm -f " ,persistent-files "\n}\n"
|
("ps1" `("try {\n"
|
||||||
"_doomrun() {\n " ,command "\n}\n"
|
,(cl-loop for (var . val) in persisted-env
|
||||||
,(string-join persisted-env " \\\n")
|
concat (format " $__%s = $env:%s; $env:%s = %S\n "
|
||||||
,(cl-loop for (envvar . val) in envvars
|
var var var val))
|
||||||
if val
|
,command
|
||||||
concat (format "%s=%s \\\n" envvar (shell-quote-argument val)))
|
"\n} finally {\n"
|
||||||
,(format "PATH=\"%s%s$PATH\" \\\n"
|
,(cl-loop for file in persistent-files
|
||||||
(doom-path doom-emacs-dir "bin")
|
concat (format " Remove-Item -Path %S\n " file))
|
||||||
path-separator)
|
,(cl-loop for (var . val) in envvars
|
||||||
"_doomrun \"$@\"\n"))
|
concat (format " $env:%s = $__%s\n " var var))
|
||||||
("ps1" `("try {\n"
|
"\n}")))))
|
||||||
,(cl-loop for (envvar . val) in envvars
|
(doom-log "_doomrun: %s %s"
|
||||||
if val
|
(cl-loop for (var . val) in persisted-env
|
||||||
concat (format " $__%s = $env:%s; $env:%s = %s\\\n " envvar envvar envvar (shell-quote-argument val)))
|
concat (format "%s=%s \\\n" var (shell-quote-argument val)))
|
||||||
,command
|
command)
|
||||||
"\n} finally {\n"
|
|
||||||
,(cl-loop for file in persistent-files
|
|
||||||
concat (format " Remote-Item -Path %S\n " file))
|
|
||||||
,(cl-loop for (envvar . val) in envvars
|
|
||||||
if val
|
|
||||||
concat (format " $env:%s = $__%s\\\n " envvar envvar))
|
|
||||||
"\n}"))))))
|
|
||||||
(doom-log "_doomrun: %s %s" (string-join persisted-env " ") command)
|
|
||||||
(doom-log "_doomcleanup: %s" persistent-files)
|
(doom-log "_doomcleanup: %s" persistent-files)
|
||||||
;; Error code 254 is special: it indicates to the caller that the
|
;; Error code 254 is special: it indicates to the caller that the
|
||||||
;; post-script should be executed after this session ends. It's up to
|
;; post-script should be executed after this session ends. It's up to
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue