From cee1cbfd54375cdece23d4741ced6b0c7091f6d9 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Thu, 15 Sep 2022 12:24:37 -0700 Subject: 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). --- lisp/eshell/esh-util.el | 55 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'lisp/eshell/esh-util.el') 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 -- cgit v1.2.3