Function: eshell-expand-glob

eshell-expand-glob is a byte-compiled function defined in em-glob.el.gz.

Signature

(eshell-expand-glob GLOB)

Documentation

Return a list of files matched by GLOB.

Each globbing character in GLOB should have a non-nil value for the text property eshell-glob-char (e.g. by eshell-parse-glob-chars) in order for it to have syntactic meaning; otherwise, this function treats the character literally.

This function is primarily intended for use within Eshell command forms. If you want to use an ordinary string as a glob, use eshell-extended-glob instead.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/em-glob.el.gz
(defun eshell-expand-glob (glob)
  "Return a list of files matched by GLOB.
Each globbing character in GLOB should have a non-nil value for the text
property `eshell-glob-char' (e.g. by `eshell-parse-glob-chars') in order
for it to have syntactic meaning; otherwise, this function treats the
character literally.

This function is primarily intended for use within Eshell command
forms.  If you want to use an ordinary string as a glob, use
`eshell-extended-glob' instead."
  (let ((globs (eshell-glob-convert glob))
        eshell-glob-matches message-shown)
    (unwind-protect
        ;; After examining GLOB, make sure we actually got some globs
        ;; before computing the results.  We can get zero globs for
        ;; remote file names using "~", like "/ssh:remote:~/file.txt".
        ;; During Eshell argument parsing, we can't always be sure if
        ;; the "~" is a home directory reference or part of a glob
        ;; (e.g. if the argument was assembled from variables).
        (when (cadr globs)
          (apply #'eshell-glob-entries globs))
      (when message-shown
        (message nil)))
    (cond
     (eshell-glob-matches
      (sort eshell-glob-matches #'string<))
     ((and eshell-error-if-no-glob (cadr globs))
      (error "No matches found: %s" glob))
     (t
      (let ((result (substring-no-properties glob)))
        (if eshell-glob-splice-results (list result) result))))))