在 macOS 下 dired 中打开 tar 文件使用 tar-untar-buffer
不知道为什么会出现 PaxHeader
和一堆错误的 ._
开头的文件.
虽然不清楚为什么, 但是感觉完全可以不用 tar-untar-buffer
直接调用 tar
来解决这个问题, 如下:
(cl-defmacro extcase (file-name &body cases)
"Case by `file-name' extension.
Return `t' if matches, otherwise `nil'.
Syntax:
* `file-name': expr for file-name
* `cases': case should be like (ext-type . progn)
+ `ext-type' can be
+ string for single ext pattern
+ list of string for multiple ext pattern
+ `:otherwise' (should be the last case)
for otherwise
"
(let ((ext-name (gensym "EXT-NAME")))
`(let ((,ext-name (file-name-extension ,file-name)))
(cond
,@(cl-loop for (ext-type* . progn) in cases
if (listp ext-type*)
collect `((or ,@(mapcar (lambda (ext-type)
`(string= ,ext-name ,ext-type))
ext-type*))
,@progn
t)
else if (stringp ext-type*)
collect `((string= ,ext-name ,ext-type*) ,@progn)
else if (eq ext-type* :otherwise)
collect `(t ,@progn nil)
while (not (eq ext-type* :otherwise)))))))
(defun ryo.dired:dired-uncompress-file ()
"In Dired, uncompress this file (if it is a tar file) right here. "
(interactive)
(let ((file-name (dired-get-file-for-visit)))
(when (extcase file-name
(("gz" "tar")
(message (concat "Untar " file-name " ..."))
(shell-command (concat "tar xzf " file-name)))
("zip"
(message (concat "Unzip " file-name " ..."))
(shell-command (concat "unzip " file-name)))
(:otherwise
(message "Not a known compressed file")))
(message (concat "Finish uncompress " file-name))
(revert-buffer-quick))))
;; 可以绑定一个按键之类的, 比如 `X'
(顺带问问为啥会出现 ._
和 PaxHeader