在 Emacs 的 dired 和 tramp 中异步运行 rsync
emacs
![](/data/attachment/album/201903/21/204550do9qxij89ztwiojw.jpg)


[Trần Xuân Trường](https://truongtx.me/about.html) 写的 [tmtxt-dired-async](https://truongtx.me/tmtxt-dired-async.html) 是一个不为人知的 Emacs 包，它可以扩展 dired（Emacs 内置的文件管理器），使之可以异步地运行 `rsync` 和其他命令 (例如压缩、解压缩和下载）。


这意味着你可以拷贝上 GB 的目录而不影响 Emacs 的其他任务。


它的一个功能时让你可以通过 `C-c C-a` 从不同位置添加任意多的文件到一个等待列表中，然后按下 `C-c C-v` 异步地使用 `rsync` 将整个等待列表中的文件同步到目标目录中。光这个功能就值得一试了。


例如这里将 arduino 1.9 的 beta 存档同步到另一个目录中：


![](/data/attachment/album/201903/21/204741q5xxlrx2xz28jh2h.png)


整个进度完成后，底部的窗口会在 5 秒后自动退出。下面是异步解压上面的 arduino 存档后出现的另一个会话：


![](/data/attachment/album/201903/21/204744yphj8jdpj8zfdp77.png)


这个包进一步增加了我 dired 配置的实用性。


我刚刚贡献了 [一个拉取请求来允许 tmtxt-dired-async 同步到远程 tramp 目录中](https://github.com/tmtxt/tmtxt-dired-async/pull/6)，而且我立即使用该功能来将上 GB 的新照片传输到 Linux 服务器上。


若你想配置 tmtxt-dired-async，下载 [tmtxt-async-tasks.el](https://github.com/tmtxt/tmtxt-async-tasks)（被依赖的库）以及 [tmtxt-dired-async.el](https://github.com/tmtxt/tmtxt-dired-async)（若你想让它支持 tramp，请确保合并使用了我的拉取请求）到 `~/.emacs.d/` 目录中，然后添加下面配置：



```
;; no MELPA packages of this, so we have to do a simple check here
(setq dired-async-el (expand-file-name "~/.emacs.d/tmtxt-dired-async.el"))
(when (file-exists-p dired-async-el)
  (load (expand-file-name "~/.emacs.d/tmtxt-async-tasks.el"))
  (load dired-async-el)
  (define-key dired-mode-map (kbd "C-c C-r") 'tda/rsync)
  (define-key dired-mode-map (kbd "C-c C-z") 'tda/zip)
  (define-key dired-mode-map (kbd "C-c C-u") 'tda/unzip)

  (define-key dired-mode-map (kbd "C-c C-a") 'tda/rsync-multiple-mark-file)
  (define-key dired-mode-map (kbd "C-c C-e") 'tda/rsync-multiple-empty-list)
  (define-key dired-mode-map (kbd "C-c C-d") 'tda/rsync-multiple-remove-item)
  (define-key dired-mode-map (kbd "C-c C-v") 'tda/rsync-multiple)

  (define-key dired-mode-map (kbd "C-c C-s") 'tda/get-files-size)

  (define-key dired-mode-map (kbd "C-c C-q") 'tda/download-to-current-dir))
```

祝你开心！




---


via: <https://vxlabs.com/2018/03/30/asynchronous-rsync-with-emacs-dired-and-tramp/>


作者：[cpbotha](https://vxlabs.com/author/cpbotha/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[lujun9972](https://github.com/lujun9972) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
# Asynchronous rsync with Emacs, dired and tramp.

## Contents

[tmtxt-dired-async](https://truongtx.me/tmtxt-dired-async.html) by [Trần Xuân Trường](https://truongtx.me/about.html) is an unfortunately lesser known Emacs package which extends dired, the Emacs file manager, to be able to run rsync and other commands (zip, unzip, downloading) asynchronously.

This means you can copy gigabytes of directories around whilst still happily continuing with all of your other tasks in the Emacs operating system.

It has a feature where you can add any number of files from different locations into a wait list with `C-c C-a`

, and then asynchronously rsync the whole wait list into a final destination directory with `C-c C-v`

. This alone is worth the price of admission.

For example here it is pointlessly rsyncing the arduino 1.9 beta archive to another directory:

When the process is complete, the window at the bottom will automatically be killed after 5 seconds. Here is a separate session right after the asynchronous unzipping of the above-mentioned arduino archive:

This package has further increased the utility of my dired configuration.

I just contributed [a pull request that enables tmtxt-dired-async to rsync to remote tramp-based directories](https://github.com/tmtxt/tmtxt-dired-async/pull/6), and I immediately used this new functionality to sort a few gigabytes of new photos onto the Linux server.

To add tmtxt-dired-async to your config, download [tmtxt-async-tasks.el](https://github.com/tmtxt/tmtxt-async-tasks) (a required library) and [tmtxt-dired-async.el](https://github.com/tmtxt/tmtxt-dired-async) (check that my PR is in there if you plan to use this with tramp) into your `~/.emacs.d/`

and add the following to your config:

;; no MELPA packages of this, so we have to do a simple check here (setq dired-async-el (expand-file-name "~/.emacs.d/tmtxt-dired-async.el")) (when (file-exists-p dired-async-el) (load (expand-file-name "~/.emacs.d/tmtxt-async-tasks.el")) (load dired-async-el) (define-key dired-mode-map (kbd "C-c C-r") 'tda/rsync) (define-key dired-mode-map (kbd "C-c C-z") 'tda/zip) (define-key dired-mode-map (kbd "C-c C-u") 'tda/unzip) (define-key dired-mode-map (kbd "C-c C-a") 'tda/rsync-multiple-mark-file) (define-key dired-mode-map (kbd "C-c C-e") 'tda/rsync-multiple-empty-list) (define-key dired-mode-map (kbd "C-c C-d") 'tda/rsync-multiple-remove-item) (define-key dired-mode-map (kbd "C-c C-v") 'tda/rsync-multiple) (define-key dired-mode-map (kbd "C-c C-s") 'tda/get-files-size) (define-key dired-mode-map (kbd "C-c C-q") 'tda/download-to-current-dir))

Enjoy!