Function: tramp-find-executable
tramp-find-executable is a byte-compiled function defined in
tramp-sh.el.gz.
Signature
(tramp-find-executable VEC PROGNAME DIRLIST &optional IGNORE-TILDE IGNORE-PATH)
Documentation
Search for PROGNAME in $PATH and all directories mentioned in DIRLIST.
First arg VEC specifies the connection, PROGNAME is the program to search for, and DIRLIST gives the list of directories to search. If IGNORE-TILDE is non-nil, directory names starting with "~" will be ignored. If IGNORE-PATH is non-nil, searches 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.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
(defun tramp-find-executable
(vec progname dirlist &optional ignore-tilde ignore-path)
"Search for PROGNAME in $PATH and all directories mentioned in DIRLIST.
First arg VEC specifies the connection, PROGNAME is the program
to search for, and DIRLIST gives the list of directories to
search. If IGNORE-TILDE is non-nil, directory names starting
with \"~\" will be ignored. If IGNORE-PATH is non-nil, searches
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."
(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))))
(let ((command
(concat
(when dirlist (format "PATH=%s " (string-join dirlist ":")))
"command -v " progname))
(pipe-buf (tramp-get-remote-pipe-buf vec))
tmpfile chunk chunksize)
(when (if (length< command pipe-buf)
(tramp-send-command-and-check vec command)
;; Use a temporary file. We cannot use `write-region'
;; because setting the remote path happens in the early
;; connection handshake, and not all external tools are
;; determined yet.
(setq command (concat command "\n")
tmpfile (tramp-make-tramp-temp-file vec))
(while (not (string-empty-p command))
(setq chunksize (min (length command) (/ pipe-buf 2))
chunk (substring command 0 chunksize)
command (substring command chunksize))
(tramp-send-command
vec (format "printf \"%%b\" \"$*\" %s >>%s"
(tramp-shell-quote-argument chunk)
(tramp-shell-quote-argument tmpfile))))
(tramp-send-command-and-check
vec (format ". %s && rm -f %s" tmpfile tmpfile)))
(string-trim
(tramp-get-buffer-string (tramp-get-connection-buffer vec))))))