Function: eshell-grep

eshell-grep is a byte-compiled function defined in em-unix.el.gz.

Signature

(eshell-grep COMMAND ARGS &optional MAYBE-USE-OCCUR)

Documentation

Generic service function for the various grep aliases.

It calls Emacs's grep utility if the command is not redirecting output, and if it's not part of a command pipeline. Otherwise, it calls the external command.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/em-unix.el.gz
(defun eshell-grep (command args &optional maybe-use-occur)
  "Generic service function for the various grep aliases.
It calls Emacs's grep utility if the command is not redirecting output,
and if it's not part of a command pipeline.  Otherwise, it calls the
external command."
  (if (and maybe-use-occur eshell-no-grep-available)
      (eshell-poor-mans-grep args)
    (if (or eshell-plain-grep-behavior
	    (not (and (eshell-interactive-output-p)
		      (not eshell-in-pipeline-p)
		      (not eshell-in-subcommand-p))))
	(throw 'eshell-replace-command
	       (eshell-parse-command (concat "*" command)
				     (eshell-stringify-list
				      (flatten-tree args))))
      (let* ((args (mapconcat 'identity
			      (mapcar 'shell-quote-argument
				      (eshell-stringify-list
				       (flatten-tree args)))
			      " "))
	     (cmd (format "%s -nH %s"
			  (pcase command
			    ("egrep" "grep -E")
			    ("fgrep" "grep -F")
			    (x x))
			  args))
	     compilation-scroll-output)
	(grep cmd)))))