我想在dired或类似dired的缓冲区中运行解压缩(甚至zip)。有这样的事吗?我想要与Nautilus文件管理器类似的东西:即选择文件然后按键击以将这些文件放入新的存档文件中。

谢谢

有帮助吗?

解决方案

你有选择......

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

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

现在,dired中的 Z 键将识别.zip扩展名并解压缩.zip存档。已经支持 gunzip bunzip2 uncompress dictunzip

如果要标记文件并将其添加到.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<*>quot; 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 " ")) 

其他提示

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

! zip foo.zip * <RET>

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

zip-archive模式允许您以类似方式浏览zip文件。它应该附带最新版本的GNU emacs,并且在您访问扩展名为.zip的文件时将默认使用。在这种模式下,您可以将单个文件提取到缓冲区中,然后使用 C-x C-s 保存它们。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top