Function: eshell/which

eshell/which is a byte-compiled function defined in esh-cmd.el.gz.

Signature

(eshell/which COMMAND &rest NAMES)

Documentation

Identify the COMMAND, and where it is located.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/esh-cmd.el.gz
(defun eshell/which (command &rest names)
  "Identify the COMMAND, and where it is located."
  (dolist (name (cons command names))
    (let (program alias direct)
      (if (eq (aref name 0) eshell-explicit-command-char)
	  (setq name (substring name 1)
		direct t))
      (if (and (not direct)
	       (fboundp 'eshell-lookup-alias)
	       (setq alias
		     (eshell-lookup-alias name)))
	  (setq program
		(concat name " is an alias, defined as \""
			(cadr alias) "\"")))
      (unless program
        (setq program
              (let* ((esym (eshell-find-alias-function name))
                     (sym (or esym (intern-soft name))))
                (if (and (or esym (and sym (fboundp sym)))
                         (or eshell-prefer-lisp-functions (not direct)))
                    (or (with-output-to-string
                          (require 'help-fns)
                          (princ (format "%s is " sym))
                          (help-fns-function-description-header sym))
                        name)
                  (eshell-search-path name)))))
      (if (not program)
	  (eshell-error (format "which: no %s in (%s)\n"
				name (getenv "PATH")))
	(eshell-printn program)))))