diff options
author | Jim Porter <jporterbugs@gmail.com> | 2022-09-15 12:24:37 -0700 |
---|---|---|
committer | Jim Porter <jporterbugs@gmail.com> | 2022-10-17 18:48:52 -0700 |
commit | cee1cbfd54375cdece23d4741ced6b0c7091f6d9 (patch) | |
tree | 482d4bf98473742958b4ce4f1fba1c3e305aa093 /lisp/eshell | |
parent | 7c41016fca5ab0638f1e2fed260e2ee41f3400c2 (diff) | |
download | emacs-cee1cbfd54375cdece23d4741ced6b0c7091f6d9.tar.gz emacs-cee1cbfd54375cdece23d4741ced6b0c7091f6d9.tar.bz2 emacs-cee1cbfd54375cdece23d4741ced6b0c7091f6d9.zip |
Improve handling of $PATH in Eshell for remote directories
* lisp/eshell/esh-util.el (eshell-path-env, eshell-parse-colon-path):
Make obsolete.
(eshell-path-env-list): New variable.
(eshell-connection-default-profile): New connection-local profile.
(eshell-get-path): Reimplement using 'eshell-path-env-list'; add
LITERAL-P argument.
(eshell-set-path): New function.
* lisp/eshell/esh-var.el (eshell-variable-aliases-list): Add entry for
$PATH.
(eshell-var-initialize): Add 'eshell-path-env-list' to
'eshell-subcommand-bindings'.
* lisp/eshell/esh-ext.el (eshell-search-path): Use 'file-name-concat'
instead of 'concat'.
(eshell/addpath): Use 'eshell-get-path' and 'eshell-set-path'.
* lisp/net/tramp-integration.el: Only apply Eshell hooks when
'eshell-path-env-list' is unbound.
* test/lisp/eshell/esh-var-tests.el
(esh-var-test/path-var/local-directory)
(esh-var-test/path-var/remote-directory, esh-var-test/path-var/set)
(esh-var-test/path-var/set-locally)
(esh-var-test/path-var-preserve-across-hosts): New tests.
* test/lisp/eshell/esh-ext-tests.el: New file.
* test/lisp/eshell/eshell-tests-helpers.el
(with-temp-eshell): Set 'eshell-last-dir-ring-file-name' to nil.
(eshell-tests-remote-accessible-p, eshell-last-input)
(eshell-last-output): New functions.
(eshell-match-output, eshell-match-output--explainer): Use
'eshell-last-input' and 'eshell-last-output'.
* doc/misc/eshell.texi (Variables): Document $PATH.
* etc/NEWS: Announce this change (bug#57556).
Diffstat (limited to 'lisp/eshell')
-rw-r--r-- | lisp/eshell/esh-ext.el | 23 | ||||
-rw-r--r-- | lisp/eshell/esh-util.el | 55 | ||||
-rw-r--r-- | lisp/eshell/esh-var.el | 12 |
3 files changed, 70 insertions, 20 deletions
diff --git a/lisp/eshell/esh-ext.el b/lisp/eshell/esh-ext.el index 98902fc6f23..d513d750d9d 100644 --- a/lisp/eshell/esh-ext.el +++ b/lisp/eshell/esh-ext.el @@ -77,7 +77,7 @@ but Eshell will be able to understand (let ((list (eshell-get-path)) suffixes n1 n2 file) (while list - (setq n1 (concat (car list) name)) + (setq n1 (file-name-concat (car list) name)) (setq suffixes eshell-binary-suffixes) (while suffixes (setq n2 (concat n1 (car suffixes))) @@ -239,17 +239,16 @@ causing the user to wonder if anything's really going on..." (?h "help" nil nil "display this usage message") :usage "[-b] PATH Adds the given PATH to $PATH.") - (if args - (progn - (setq eshell-path-env (getenv "PATH") - args (mapconcat #'identity args path-separator) - eshell-path-env - (if prepend - (concat args path-separator eshell-path-env) - (concat eshell-path-env path-separator args))) - (setenv "PATH" eshell-path-env)) - (dolist (dir (parse-colon-path (getenv "PATH"))) - (eshell-printn dir))))) + (let ((path (eshell-get-path t))) + (if args + (progn + (setq path (if prepend + (append args path) + (append path args))) + (eshell-set-path path) + (string-join path (path-separator))) + (dolist (dir path) + (eshell-printn dir)))))) (put 'eshell/addpath 'eshell-no-numeric-conversions t) (put 'eshell/addpath 'eshell-filename-arguments t) diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el index 9258ca5e40e..9b464a0a137 100644 --- a/lisp/eshell/esh-util.el +++ b/lisp/eshell/esh-util.el @@ -249,17 +249,60 @@ trailing newlines removed. Otherwise, this behaves as follows: It might be different from \(getenv \"PATH\"), when `default-directory' points to a remote host.") -(defun eshell-get-path () +(make-obsolete-variable 'eshell-path-env 'eshell-get-path "29.1") + +(defvar-local eshell-path-env-list nil) + +(connection-local-set-profile-variables + 'eshell-connection-default-profile + '((eshell-path-env-list . nil))) + +(connection-local-set-profiles + '(:application eshell) + 'eshell-connection-default-profile) + +(defun eshell-get-path (&optional literal-p) "Return $PATH as a list. -Add the current directory on MS-Windows." - (eshell-parse-colon-path - (if (eshell-under-windows-p) - (concat "." path-separator eshell-path-env) - eshell-path-env))) +If LITERAL-P is nil, return each directory of the path as a full, +possibly-remote file name; on MS-Windows, add the current +directory as the first directory in the path as well. + +If LITERAL-P is non-nil, return the local part of each directory, +as the $PATH was actually specified." + (with-connection-local-application-variables 'eshell + (let ((remote (file-remote-p default-directory)) + (path + (or eshell-path-env-list + ;; If not already cached, get the path from + ;; `exec-path', removing the last element, which is + ;; `exec-directory'. + (setq-connection-local eshell-path-env-list + (butlast (exec-path)))))) + (when (and (not literal-p) + (not remote) + (eshell-under-windows-p)) + (push "." path)) + (if (and remote (not literal-p)) + (mapcar (lambda (x) (file-name-concat remote x)) path) + path)))) + +(defun eshell-set-path (path) + "Set the Eshell $PATH to PATH. +PATH can be either a list of directories or a string of +directories separated by `path-separator'." + (with-connection-local-application-variables 'eshell + (setq-connection-local + eshell-path-env-list + (if (listp path) + path + ;; Don't use `parse-colon-path' here, since we don't want + ;; the additonal translations it does on each element. + (split-string path (path-separator)))))) (defun eshell-parse-colon-path (path-env) "Split string with `parse-colon-path'. Prepend remote identification of `default-directory', if any." + (declare (obsolete nil "29.1")) (let ((remote (file-remote-p default-directory))) (if remote (mapcar diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el index caf143e1a1a..57ea42f4933 100644 --- a/lisp/eshell/esh-var.el +++ b/lisp/eshell/esh-var.el @@ -156,7 +156,14 @@ if they are quoted with a backslash." ("LINES" ,(lambda () (window-body-height nil 'remap)) t t) ("INSIDE_EMACS" eshell-inside-emacs t) - ;; for eshell-cmd.el + ;; for esh-ext.el + ("PATH" (,(lambda () (string-join (eshell-get-path t) (path-separator))) + . ,(lambda (_ value) + (eshell-set-path value) + value)) + t t) + + ;; for esh-cmd.el ("_" ,(lambda (indices quoted) (if (not indices) (car (last eshell-last-arguments)) @@ -249,7 +256,8 @@ copied (a.k.a. \"exported\") to the environment of created subprocesses." (setq-local eshell-subcommand-bindings (append '((process-environment (eshell-copy-environment)) - (eshell-variable-aliases-list eshell-variable-aliases-list)) + (eshell-variable-aliases-list eshell-variable-aliases-list) + (eshell-path-env-list eshell-path-env-list)) eshell-subcommand-bindings)) (setq-local eshell-special-chars-inside-quoting |