           (when revert-buffer-function
             (funcall revert-buffer-function))
           (when-let* ((oldest-new-file (car (last (seq-sort #'file-newer-than-file-p
-                                                            (seq-difference (dwim-shell--buffer-files)
+                                                            (seq-difference (dwim-shell--default-directory)
                                                                             files-before))))))
             (dired-jump nil oldest-new-file)))
         (when on-completion

  (cl-assert (equal major-mode 'dired-mode) nil "Not in dired-mode")
  (dwim-shell-execute-script script name (dired-get-marked-files) utils
                             post-process-template on-completion))

(defun dwim-shell--dired-files ()
  "List of files in current dired buffer."
  (cl-assert (equal major-mode 'dired-mode) nil "Not in dired-mode")
  (save-excursion
    (goto-char (point-min))
    (let (r)
      (while (= 0 (forward-line))
        (when-let (filename (dired-get-filename nil t))
          (push filename r)))
      (nreverse r))))

(defun dwim-shell-execute-script (script name files utils &optional post-process-template on-completion)
  "Execute SCRIPT, using buffer NAME, FILES, and bin UTILS."

                (funcall revert-buffer-function))
              (dwim-shell--dired-files))))))

(defun dwim-shell--dired-files ()
  "List of files in current dired buffer."
  (cl-assert (equal major-mode 'dired-mode) nil "Not in dired-mode")
  (save-excursion
    (goto-char (point-min))
    (let (r)
      (while (= 0 (forward-line))
        (when-let (filename (dired-get-filename nil t))
          (push filename r)))
      (nreverse r))))

(defun dwim-shell--finalize (calling-buffer files-before process progress-reporter on-completion)
  (when progress-reporter
    (progress-reporter-done progress-reporter))
