]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix tramp-find-executable
authorMichael Albinus <michael.albinus@gmx.de>
Tue, 25 Feb 2025 08:37:28 +0000 (09:37 +0100)
committerEshel Yaron <me@eshelyaron.com>
Wed, 26 Feb 2025 09:38:23 +0000 (10:38 +0100)
* lisp/net/tramp-sh.el (tramp-find-executable): Use "command -pv",
it isbetter supported in different shells.  (Bug#76521)

(cherry picked from commit 53eec34da1bf2fb9381680734a99f3fb11225787)

lisp/net/tramp-sh.el

index 080a74405d1ee374e1f0d3b96b0f64d5a74ba132..c78234e57a33d9d65999d7796fb37d37b300dc76 100644 (file)
@@ -4098,25 +4098,23 @@ only in DIRLIST.
 Returns the absolute file name of PROGNAME, if found, and nil otherwise.
 
 This function expects to be in the right *tramp* buffer."
-  (with-current-buffer (tramp-get-connection-buffer vec)
-    (unless ignore-path
-      (setq dirlist (cons "$PATH" dirlist)))
-    (when ignore-tilde
-      ;; Remove all ~/foo directories from dirlist.
-      (let (newdl d)
-       (while dirlist
-         (setq d (car dirlist)
-               dirlist (cdr dirlist))
-         (unless (char-equal ?~ (aref d 0))
-           (setq newdl (cons d newdl))))
-       (setq dirlist (nreverse newdl))))
-    (tramp-send-command
-     vec (format "%s type -P %s 2>%s"
-                (if dirlist (concat "PATH=" (string-join dirlist ":")) "")
-                progname (tramp-get-remote-null-device vec)))
-    (goto-char (point-min))
-    (when (search-forward-regexp "/" nil 'noerror)
-      (string-trim (buffer-substring (match-beginning 0) (point-max))))))
+  (unless ignore-path
+    (setq dirlist (cons "$PATH" dirlist)))
+  (when ignore-tilde
+    ;; Remove all ~/foo directories from dirlist.
+    (let (newdl d)
+      (while dirlist
+       (setq d (car dirlist)
+             dirlist (cdr dirlist))
+       (unless (char-equal ?~ (aref d 0))
+         (setq newdl (cons d newdl))))
+      (setq dirlist (nreverse newdl))))
+  (when (tramp-send-command-and-check
+         vec (format "(unalias %s; %s command -pv %s)"
+                     progname
+                     (if dirlist (concat "PATH=" (string-join dirlist ":")) "")
+                     progname))
+    (string-trim (tramp-get-buffer-string (tramp-get-connection-buffer vec)))))
 
 ;; On hydra.nixos.org, the $PATH environment variable is too long to
 ;; send it.  This is likely not due to PATH_MAX, but PIPE_BUF.  We