I've written the following snippet which (as far as I can tell) does what you're looking for from the point of view of the ! command.
It does the following:
- Takes the files that would have operated on by dired-do-shell-command (i.e. the
!
key). This will be either the marked files, the file under point if nothing is marked or the files specified by a prefix arg. As far as I can tell this is the same as the behavior you get from !
- Downloads a local (temporary) copy of each of the files in directory specified by
temporary-file-directory
on your system.
- Runs
dired-do-shell-command
in that directory on that file or files
(defun dired-do-local-command ()
(interactive)
(let* ((marked-files (dired-get-marked-files nil current-prefix-arg))
(local-tmp-files (mapcar #'file-local-copy marked-files))
(num-files (length local-tmp-files))
(default-directory temporary-file-directory)
(command (dired-read-shell-command "! on %s: " num-files marked-files)))
(dired-do-shell-command command num-files local-tmp-files)))
You can bind this to a key in dired mode (I've chosen ") with
(define-key dired-mode-map (kbd "\"") 'dired-do-local-command)
and it should behave similarly to the ! key.
default-directory
to a local path before callingshell-command
. However, given that you would need to specify the remote file path using a non-tramp syntax -- and what that syntax was (if it existed at all) would be dependent on the command you were running -- it doesn't seem to me like an obvious thing to try to do.file-local-copy
is a function which does the copy-to-a-local-temp-file part of that approach.