25

我想在 dired 或类似 dired 的缓冲区中运行 unzip(甚至 zip)。有这样的吗?我想要类似于 Nautilus 文件管理器中的内容:即选择文件,然后按下键将这些文件放入新的存档文件中。

谢谢

4

2 回答 2

35

你有选择...

要解压缩 .zip 文件,您只需添加到变量'dired-compress-file-suffixes

(eval-after-load "dired-aux"
   '(add-to-list 'dired-compress-file-suffixes 
                 '("\\.zip\\'" ".zip" "unzip")))

现在Z,dired 中的密钥将识别 .zip 扩展名并解压缩 .zip 存档。已经支持的是gunzipbunzip2和。uncompressdictunzip

如果您想标记文件并将它们添加到 .zip 存档中,您可以使用以下命令z绑定以压缩标记文件集:

(eval-after-load "dired"
  '(define-key dired-mode-map "z" 'dired-zip-files))
(defun dired-zip-files (zip-file)
  "Create an archive containing the marked files."
  (interactive "sEnter name of zip file: ")

  ;; create the zip file
  (let ((zip-file (if (string-match ".zip$" zip-file) zip-file (concat zip-file ".zip"))))
    (shell-command 
     (concat "zip " 
             zip-file
             " "
             (concat-string-list 
              (mapcar
               '(lambda (filename)
                  (file-name-nondirectory filename))
               (dired-get-marked-files))))))

  (revert-buffer)

  ;; remove the mark on all the files  "*" to " "
  ;; (dired-change-marks 42 ?\040)
  ;; mark zip file
  ;; (dired-mark-files-regexp (filename-to-regexp zip-file))
  )

(defun concat-string-list (list) 
   "Return a string which is a concatenation of all elements of the list separated by spaces" 
    (mapconcat '(lambda (obj) (format "%s" obj)) list " ")) 
于 2009-09-16T10:11:09.977 回答
23

要压缩文件,请打开目录中的目录。标记要压缩的文件m。然后输入

! zip foo.zip * <RET>

要从 dired 中提取整个存档,您可以标记文件并运行& unzip,就像在 shell 中一样。

zip-archive 模式将允许您以类似 dired 的方式浏览 zip 文件。它应该随最新版本的 GNU emacs 一起提供,并且在您访问具有 .zip 扩展名的文件时默认使用。在此模式下,您可以将单个文件提取到缓冲区中,并从那里使用C-x C-s.

于 2009-09-16T07:04:43.113 回答