如何在 Emacs 中解压/解压

发布于 2024-08-05 01:56:12 字数 119 浏览 9 评论 0原文

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

谢谢

I would like to run unzip (or even zip) within dired or a dired-like buffer. Is there anything like this? I would like something similar as in the Nautilus file manager: i.e., selecting files and then pressing a keystroke to get these files into a new archive file.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦毁影碎の 2024-08-12 01:56:12

您有选择...

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

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

现在的 Z 键dired 将识别 .zip 扩展名并解压缩 .zip 存档。已支持的有 gunzipbunzip2uncompressdictunzip

如果您想标记文件并将其添加到 .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 " ")) 

You've got options...

To uncompress a .zip file, you just need to add to the variable 'dired-compress-file-suffixes

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

Now the Z key in dired will recognize the .zip extension and uncompress a .zip archive. Already supported are gunzip, bunzip2, uncompress and dictunzip.

If you want to mark files and add them to a .zip archive you can use the following to make z bound to zip the set of marked files:

(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 " ")) 
森林散布 2024-08-12 01:56:12

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

! zip foo.zip * <RET>

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

zip 存档模式将允许您以类似 dired 的方式浏览 zip 文件。它应该随最新版本的 GNU emacs 一起提供,并且当您访问扩展名为 .zip 的文件时将默认使用它。在此模式下,您可以将单个文件提取到缓冲区中,然后使用 Cx Cs 保存它们。

To zip files, open the directory in dired. Mark the files you want to zip with m. Then type

! zip foo.zip * <RET>

To extract an entire archive from dired you can mark a file and run & unzip, just as you would in a shell.

zip-archive mode will allow you to browse zip files in a dired-like fashion. It should come with recent versions of GNU emacs and will be used by default when you visit a file with the .zip extension. From this mode you can extract individual files into a buffer, and from there save them with C-x C-s.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文