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."
  (with-current-buffer (tramp-get-connection-buffer vec)
    (let (result)
      ;; Check whether the executable is in $PATH.  "which(1)" does not
      ;; report always a correct error code; therefore we check the
      ;; number of words it returns.  "SunOS 5.10" (and maybe "SunOS
      ;; 5.11") have problems with this command, we disable the call
      ;; therefore.
      (unless (or ignore-path (tramp-check-remote-uname vec tramp-sunos-unames))
	(tramp-send-command vec (format "which \\%s | wc -w" progname))
	(goto-char (point-min))
	(if (looking-at-p (rx bol (* blank) "1" eol))
	    (setq result (concat "\\" progname))))
      (unless result
	(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 (concat "while read d; "
			 "do if test -x $d/%s && test -f $d/%s; "
			 "then echo tramp_executable $d/%s; "
			 "break; fi; done <<'%s'\n"
			 "%s\n%s")
		 progname progname progname
		 tramp-end-of-heredoc
		 (string-join dirlist "\n")
		 tramp-end-of-heredoc))
	(goto-char (point-max))
	(when (search-backward "tramp_executable " nil t)
	  (skip-chars-forward "^ ")
	  (skip-chars-forward " ")
	  (setq result (buffer-substring (point) (line-end-position)))))
    result)))