Function: eshell-parse-redirection
eshell-parse-redirection is a byte-compiled function defined in
esh-io.el.gz.
Signature
(eshell-parse-redirection)
Documentation
Parse an output redirection, such as 2> or >&.
Source Code
;; Defined in /usr/src/emacs/lisp/eshell/esh-io.el.gz
(defun eshell-parse-redirection ()
"Parse an output redirection, such as `2>' or `>&'."
(unless (or eshell-current-quoted
eshell-current-argument-plain)
(cond
;; Copying a handle (e.g. `2>&1').
((looking-at (rx (? (group digit))
(group (or "<" ">"))
"&" (group digit)
(* (syntax whitespace))))
(let ((source (string-to-number (or (match-string 1) "1")))
(mode (cdr (assoc (match-string 2)
eshell-redirection-operators-alist)))
(target (string-to-number (match-string 3))))
(when (eq mode 'input)
(error "Eshell does not support input redirection"))
(goto-char (match-end 0))
(eshell-finish-arg (list 'eshell-copy-output-handle
source target))))
;; Shorthand for redirecting both stdout and stderr (e.g. `&>').
((looking-at (rx (or (seq (group (** 1 3 ">")) "&")
(seq "&" (group-n 1 (** 1 3 ">"))))
(* (syntax whitespace))))
(if eshell-current-argument
(eshell-finish-arg)
(goto-char (match-end 0))
(eshell-finish-arg
(let ((mode (cdr (assoc (match-string 1)
eshell-redirection-operators-alist))))
(list 'eshell-set-all-output-handles
(list 'quote mode))))))
;; Shorthand for piping both stdout and stderr (i.e. `|&').
((looking-at (rx "|&" (* (syntax whitespace))))
(if eshell-current-argument
(eshell-finish-arg)
(goto-char (match-end 0))
(eshell-finish-arg
'(eshell-copy-output-handle eshell-error-handle
eshell-output-handle)
'(eshell-operator "|"))))
;; Regular redirecting (e.g. `2>').
((looking-at (rx (? (group digit))
(group (or "<" (** 1 3 ">")))
(* (syntax whitespace))))
(if eshell-current-argument
(eshell-finish-arg)
(let ((source (if (match-string 1)
(string-to-number (match-string 1))
eshell-output-handle))
(mode (cdr (assoc (match-string 2)
eshell-redirection-operators-alist))))
(when (eq mode 'input)
(error "Eshell does not support input redirection"))
(goto-char (match-end 0))
(eshell-finish-arg
;; Note: the target will be set later by
;; `eshell-strip-redirections'.
(list 'eshell-set-output-handle
source (list 'quote mode)))))))))