[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/exec-path-from-shell 0e0af3907a 040/114: For non-POSIX she
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/exec-path-from-shell 0e0af3907a 040/114: For non-POSIX shells (mainly fish and tcsh), print vars in a standard "sh" subshell |
Date: |
Tue, 5 Sep 2023 03:59:59 -0400 (EDT) |
branch: elpa/exec-path-from-shell
commit 0e0af3907aa8a96e890771098885d7e636fe63ed
Author: Steve Purcell <steve@sanityinc.com>
Commit: Steve Purcell <steve@sanityinc.com>
For non-POSIX shells (mainly fish and tcsh), print vars in a standard "sh"
subshell
---
exec-path-from-shell.el | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/exec-path-from-shell.el b/exec-path-from-shell.el
index 75204b0312..b301b0de65 100644
--- a/exec-path-from-shell.el
+++ b/exec-path-from-shell.el
@@ -36,6 +36,15 @@
;; It also allows other environment variables to be retrieved from the
;; shell, so that Emacs will see the same values you get in a terminal.
+;; If you use a non-POSIX-standard shell like "tcsh" or "fish", your
+;; shell will be asked to execute "sh" as a subshell in order to print
+;; out the variables in a format which can be reliably parsed. "sh"
+;; must be a POSIX-compliant shell in this case.
+
+;; Note that shell variables which have not been exported as
+;; environment variables (e.g. using the "export" keyword) may not be
+;; visible to `exec-path-from-shell'.
+
;; Installation:
;; ELPA packages are available on Marmalade and MELPA. Alternatively, place
@@ -101,6 +110,10 @@ The default value denotes an interactive login shell."
(when exec-path-from-shell-debug
(apply 'message msg args)))
+(defun exec-path-from-shell--standard-shell-p (shell)
+ "Return non-nil iff SHELL supports the standard ${VAR-default} syntax."
+ (not (string-match "\\(fish\\|tcsh\\)$" shell)))
+
(defun exec-path-from-shell-printf (str &optional args)
"Return the result of printing STR in the user's shell.
@@ -119,7 +132,10 @@ shell-escaped, so they may contain $ etc."
" '__RESULT\\000" str "' "
(mapconcat #'exec-path-from-shell--double-quote args " ")))
(shell-args (append exec-path-from-shell-arguments
- (list "-c" printf-command)))
+ (list "-c"
+ (if (exec-path-from-shell--standard-shell-p
(getenv "SHELL"))
+ printf-command
+ (concat "sh -c " (shell-quote-argument
printf-command))))))
(shell (getenv "SHELL")))
(with-temp-buffer
(exec-path-from-shell--debug "Invoking shell %s with args %S" shell
shell-args)
@@ -138,17 +154,10 @@ shell-escaped, so they may contain $ etc."
Execute $SHELL according to `exec-path-from-shell-arguments'.
The result is a list of (NAME . VALUE) pairs."
- (let* ((is-tcsh (exec-path-from-shell--tcsh-p (getenv "SHELL")))
- (dollar-names (mapcar (lambda (n) (format (if is-tcsh "$%s" "${%s-}")
n)) names))
- (values (if is-tcsh
- ;; Dumb shell
- (mapcar (lambda (v)
- (exec-path-from-shell-printf "%s" (list v)))
- dollar-names)
- ;; Decent shell
- (split-string (exec-path-from-shell-printf
- (mapconcat #'identity (make-list (length
names) "%s") "\\000")
- dollar-names) "\0"))))
+ (let* ((dollar-names (mapcar (lambda (n) (format "${%s-}" n)) names))
+ (values (split-string (exec-path-from-shell-printf
+ (mapconcat #'identity (make-list (length
names) "%s") "\\000")
+ dollar-names) "\0")))
(let (result)
(while names
(prog1
- [nongnu] elpa/exec-path-from-shell ed17558245 011/114: Fix local variables block formatting, (continued)
- [nongnu] elpa/exec-path-from-shell ed17558245 011/114: Fix local variables block formatting, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell 3b280d3093 013/114: Set all variables using just one shell invocation, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell 4b2f672301 020/114: Make use of printf safer, in case env var values contain escapes (see #5), ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell 89aed99c12 021/114: Can now single-quote format argument to printf, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell 2b6651242f 018/114: Unambigiously escape the null character (fixes #5), ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell 9f034cdb97 022/114: Explicitly double-quote args, so empty var values don't mess things up, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell 95b7aee732 025/114: Use -d in place of --login for tcsh (fixes #7), ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell 96afc511bb 030/114: Add missing custom type, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell bfaa02106e 031/114: [Fix #13] Make shell arguments customizable, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell a5162e6f99 032/114: Merge pull request #14 from lunaryorn/customizable-args, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell 0e0af3907a 040/114: For non-POSIX shells (mainly fish and tcsh), print vars in a standard "sh" subshell,
ELPA Syncer <=
- [nongnu] elpa/exec-path-from-shell dccbb54b18 041/114: Add note about fish and tcsh to README, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell 7f77aa6dfb 052/114: Revert "Remove unnecessary dash to appease old csh", ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell e88cce5a93 067/114: Fix checkdoc warnings, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell 51d0931c2a 003/114: Improve suggested condition for initialization on OS X, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell 900d98a912 005/114: Improve docstrings, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell 1115e59539 033/114: Provide better info when the shell doesn't printf vars as expected, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell ad5eda1649 034/114: Require non-zero exit code, and allow debug output, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell 345ba9cb71 036/114: Don't fail when printing undefined vars if shell -e option is set, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell b09a42885c 037/114: tcsh doesn't support the ${VAR-default} syntax, ELPA Syncer, 2023/09/05
- [nongnu] elpa/exec-path-from-shell e4af0e9b44 043/114: Add MELPA badges, ELPA Syncer, 2023/09/05