          (progress-reporter))
     (if (seq-empty-p files)
         (setq script template)
-      (seq-do (lambda (file)
-                (when extensions
+      (when extensions
+        (seq-do (lambda (file)
                   (cl-assert (seq-contains-p extensions (downcase (file-name-extension file)))
                              nil "Not a .%s file" (string-join extensions " .")))
-                (setq script
-                      (concat script "\n"
-                              (dwim-shell-command--expand template file post-process-template gen-temp-dir))))
-              files))
+                files))
+      (if (dwim-shell-command--contains-multi-file-refs template)
+          (setq script (dwim-shell-command--expand-files-template template files post-process-template gen-temp-dir))
+        (seq-do (lambda (file)
+                  (setq script
+                        (concat script "\n"
+                                (dwim-shell-command--expand-file-template template file post-process-template gen-temp-dir))))
+                files)))
     (setq script (string-trim script))
     (seq-do (lambda (util)
               (cl-assert (executable-find util) nil

      (set-process-sentinel proc #'dwim-shell-command--sentinel)
      (set-process-filter proc #'dwim-shell-command--filter))))

(defun dwim-shell-command--expand (template file &optional post-process-template temp-dir)
  "Expand TEMPLATE using FILE.

Expand using <<f>> for FILE, <<fne>> for FILE without extension, and
 <<e>> for FILE extension.

  For example:

    Given FILE \"path/to/image.png\"

  (when post-process-template
    (setq template (funcall post-process-template template file)))
  template)

(defun dwim-shell-command--contains-single-file-ref (template)
  (cond ((string-match "\<\<f\>\>" template)
         "<<f>>")
        ((string-match "\<\<fne\>\>" template)
         "<<fne>>")
        ((string-match "\<\<e\>\>" template)
         "<<e>>")))

(defun dwim-shell-command--contains-multi-file-refs (template)
  (when (string-match "\<\<\\*\>\>" template)
    "<<*>>"))

(defun dwim-shell-command--default-directory-files ()
  "List of files in current buffer's `default-directory'."
