aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/eshell
diff options
context:
space:
mode:
authorJim Porter2022-09-15 12:24:37 -0700
committerJim Porter2022-10-17 18:48:52 -0700
commitcee1cbfd54375cdece23d4741ced6b0c7091f6d9 (patch)
tree482d4bf98473742958b4ce4f1fba1c3e305aa093 /lisp/eshell
parent7c41016fca5ab0638f1e2fed260e2ee41f3400c2 (diff)
downloademacs-cee1cbfd54375cdece23d4741ced6b0c7091f6d9.tar.gz
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.el23
-rw-r--r--lisp/eshell/esh-util.el55
-rw-r--r--lisp/eshell/esh-var.el12
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
77 (let ((list (eshell-get-path)) 77 (let ((list (eshell-get-path))
78 suffixes n1 n2 file) 78 suffixes n1 n2 file)
79 (while list 79 (while list
80 (setq n1 (concat (car list) name)) 80 (setq n1 (file-name-concat (car list) name))
81 (setq suffixes eshell-binary-suffixes) 81 (setq suffixes eshell-binary-suffixes)
82 (while suffixes 82 (while suffixes
83 (setq n2 (concat n1 (car suffixes))) 83 (setq n2 (concat n1 (car suffixes)))
@@ -239,17 +239,16 @@ causing the user to wonder if anything's really going on..."
239 (?h "help" nil nil "display this usage message") 239 (?h "help" nil nil "display this usage message")
240 :usage "[-b] PATH 240 :usage "[-b] PATH
241Adds the given PATH to $PATH.") 241Adds the given PATH to $PATH.")
242 (if args 242 (let ((path (eshell-get-path t)))
243 (progn 243 (if args
244 (setq eshell-path-env (getenv "PATH") 244 (progn
245 args (mapconcat #'identity args path-separator) 245 (setq path (if prepend
246 eshell-path-env 246 (append args path)
247 (if prepend 247 (append path args)))
248 (concat args path-separator eshell-path-env) 248 (eshell-set-path path)
249 (concat eshell-path-env path-separator args))) 249 (string-join path (path-separator)))
250 (setenv "PATH" eshell-path-env)) 250 (dolist (dir path)
251 (dolist (dir (parse-colon-path (getenv "PATH"))) 251 (eshell-printn dir))))))
252 (eshell-printn dir)))))
253 252
254(put 'eshell/addpath 'eshell-no-numeric-conversions t) 253(put 'eshell/addpath 'eshell-no-numeric-conversions t)
255(put 'eshell/addpath 'eshell-filename-arguments t) 254(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:
249It might be different from \(getenv \"PATH\"), when 249It might be different from \(getenv \"PATH\"), when
250`default-directory' points to a remote host.") 250`default-directory' points to a remote host.")
251 251
252(defun eshell-get-path () 252(make-obsolete-variable 'eshell-path-env 'eshell-get-path "29.1")
253
254(defvar-local eshell-path-env-list nil)
255
256(connection-local-set-profile-variables
257 'eshell-connection-default-profile
258 '((eshell-path-env-list . nil)))
259
260(connection-local-set-profiles
261 '(:application eshell)
262 'eshell-connection-default-profile)
263
264(defun eshell-get-path (&optional literal-p)
253 "Return $PATH as a list. 265 "Return $PATH as a list.
254Add the current directory on MS-Windows." 266If LITERAL-P is nil, return each directory of the path as a full,
255 (eshell-parse-colon-path 267possibly-remote file name; on MS-Windows, add the current
256 (if (eshell-under-windows-p) 268directory as the first directory in the path as well.
257 (concat "." path-separator eshell-path-env) 269
258 eshell-path-env))) 270If LITERAL-P is non-nil, return the local part of each directory,
271as the $PATH was actually specified."
272 (with-connection-local-application-variables 'eshell
273 (let ((remote (file-remote-p default-directory))
274 (path
275 (or eshell-path-env-list
276 ;; If not already cached, get the path from
277 ;; `exec-path', removing the last element, which is
278 ;; `exec-directory'.
279 (setq-connection-local eshell-path-env-list
280 (butlast (exec-path))))))
281 (when (and (not literal-p)
282 (not remote)
283 (eshell-under-windows-p))
284 (push "." path))
285 (if (and remote (not literal-p))
286 (mapcar (lambda (x) (file-name-concat remote x)) path)
287 path))))
288
289(defun eshell-set-path (path)
290 "Set the Eshell $PATH to PATH.
291PATH can be either a list of directories or a string of
292directories separated by `path-separator'."
293 (with-connection-local-application-variables 'eshell
294 (setq-connection-local
295 eshell-path-env-list
296 (if (listp path)
297 path
298 ;; Don't use `parse-colon-path' here, since we don't want
299 ;; the additonal translations it does on each element.
300 (split-string path (path-separator))))))
259 301
260(defun eshell-parse-colon-path (path-env) 302(defun eshell-parse-colon-path (path-env)
261 "Split string with `parse-colon-path'. 303 "Split string with `parse-colon-path'.
262Prepend remote identification of `default-directory', if any." 304Prepend remote identification of `default-directory', if any."
305 (declare (obsolete nil "29.1"))
263 (let ((remote (file-remote-p default-directory))) 306 (let ((remote (file-remote-p default-directory)))
264 (if remote 307 (if remote
265 (mapcar 308 (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."
156 ("LINES" ,(lambda () (window-body-height nil 'remap)) t t) 156 ("LINES" ,(lambda () (window-body-height nil 'remap)) t t)
157 ("INSIDE_EMACS" eshell-inside-emacs t) 157 ("INSIDE_EMACS" eshell-inside-emacs t)
158 158
159 ;; for eshell-cmd.el 159 ;; for esh-ext.el
160 ("PATH" (,(lambda () (string-join (eshell-get-path t) (path-separator)))
161 . ,(lambda (_ value)
162 (eshell-set-path value)
163 value))
164 t t)
165
166 ;; for esh-cmd.el
160 ("_" ,(lambda (indices quoted) 167 ("_" ,(lambda (indices quoted)
161 (if (not indices) 168 (if (not indices)
162 (car (last eshell-last-arguments)) 169 (car (last eshell-last-arguments))
@@ -249,7 +256,8 @@ copied (a.k.a. \"exported\") to the environment of created subprocesses."
249 (setq-local eshell-subcommand-bindings 256 (setq-local eshell-subcommand-bindings
250 (append 257 (append
251 '((process-environment (eshell-copy-environment)) 258 '((process-environment (eshell-copy-environment))
252 (eshell-variable-aliases-list eshell-variable-aliases-list)) 259 (eshell-variable-aliases-list eshell-variable-aliases-list)
260 (eshell-path-env-list eshell-path-env-list))
253 eshell-subcommand-bindings)) 261 eshell-subcommand-bindings))
254 262
255 (setq-local eshell-special-chars-inside-quoting 263 (setq-local eshell-special-chars-inside-quoting