代码之家  ›  专栏  ›  技术社区  ›  Damien Cassou

如何在Emacs中解压缩

  •  20
  • Damien Cassou  · 技术社区  · 15 年前

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

    2 回复  |  直到 15 年前
        1
  •  34
  •   Trey Jackson    15 年前

    你有选择。。。

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

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

    现在 Z 键入dired将识别.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$" 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 " ")) 
    
        2
  •  23
  •   p00ya    15 年前

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

    ! zip foo.zip * <RET>
    

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

    C-x C-s .