我想在OSX(10.6.8 Snow Leopard)上从dired-mode解压缩存档时自动重命名文件(如果它们已存在于目标目录中)。有没有办法在每次发生replace [filename]
提示时发送unzip
暗号r
rename
?或者,有没有更好的方法?如何在从OSX上的dired-mode解压缩时自动重命名文件
基于OSX内置的unzip --help
对话框,似乎没有命令行选项可以在文件已存在时自动重命名文件。相反,这是在unzip
正在运行时发生的终端交互式对话[例如,replace test.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename
]。这种行为是一样的我是否使用dired-do-compress
还是我自己的函数与start-process . . .
我不喜欢的
Archive Utility.app
,因为它是可见的,而解压,然后将它带我到Finder.app目标文件夹。我宁愿留在Emacs中,也不必使用Applescript带我回到那里,或者在关闭Finder.app窗口后不得不手动切换回来。
编辑(2014年7月8日):存档Utility.app具有可通过直接打开位于应用程序中设置用户首选项:/System/Library/CoreServices/Archive Utility.app
首选项包括,但不限于,是否揭示扩展项目(收费)Finder.app
Example http://www.lawlist.com/images/archive_utility_preferences.png
解压选项#1:M-x dired-do-compress
(eval-after-load "dired-aux"
'(add-to-list 'dired-compress-file-suffixes
'("\\.zip\\'" ".zip" "unzip")))
解压缩选项#2:使用OSX自带的unzip
;或使用,Archive Utility.app
(defun lawlist-zip-unzip()
(interactive)
(let* (
(lawlist-filename (file-name-nondirectory (dired-get-file-for-visit)))
(archive-filename (file-name-nondirectory (concat (file-name-sans-extension lawlist-filename) ".zip")))
(archive (dired-get-file-for-visit))
(unarchive-utility "/System/Library/CoreServices/Archive Utility.app/Contents/MacOS/Archive Utility"))
(message "[z]ip | [u]nzip")
(let* ((zip-or-unzip (read-char-exclusive)))
(cond
((eq zip-or-unzip ?z)
(when (and lawlist-filename (file-exists-p archive-filename))
(or (y-or-n-p (format "File `%s' exists; overwrite? "archive-filename))
(error "Canceled")))
(start-process "zip-file" nil "zip" archive-filename lawlist-filename))
((eq zip-or-unzip ?u)
(start-process "unzip-file" nil "unzip" archive)
;; (start-process "unzip-file" nil unarchive-utility archive)
)))
(sit-for .5)
(revert-buffer)))
错误消息:
Compress or uncompress test.zip? (y or n) y
Uncompressing /Users/HOME/Desktop/test.zip...
unzip ("/Users/HOME/Desktop/test.zip")
Archive: /Users/HOME/Desktop/test.zip
replace test.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: NULL
(assuming [N]one)
Failed to compress/Users/HOME/Desktop/test.zip
unzip
帮助对话框:
MP:~ HOME$ unzip --help
UnZip 5.52 of 28 February 2005, by Info-ZIP. Maintained by C. Spieler. Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.
Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
Default action is to extract files in list, except those in xlist, to exdir;
file[.zip] may be a wildcard. -Z => ZipInfo mode ("unzip -Z" for usage).
-p extract files to pipe, no messages -l list files (short format)
-f freshen existing files, create none -t test compressed archive data
-u update files, create if necessary -z display archive comment
-x exclude files that follow (in xlist) -d extract files into exdir
modifiers: -q quiet mode (-qq => quieter)
-n never overwrite existing files -a auto-convert any text files
-o overwrite files WITHOUT prompting -aa treat ALL files as text
-j junk paths (do not make directories) -v be verbose/print version info
-C match filenames case-insensitively -L make (some) names lowercase
-X restore UID/GID info -V retain VMS version numbers
-K keep setuid/setgid/tacky permissions -M pipe through "more" pager
Examples (see unzip.txt for more info):
unzip data1 -x joe => extract all files except joe from zipfile data1.zip
unzip -p foo | more => send contents of foo.zip via pipe into program more
unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
挖通'unzip'的源(如果它是打开的),并试图找到该标志被设置时,用户交互设置'[Y] ES,[N] O,[A] LL,[ N] one',然后查看是否可以在该命令行与参数'unzip'发送之间建立任何连接。如果是这样,利用它。 –
对于任何有兴趣的人来说,这里是来自unzip论坛的相关主题:http://www.info-zip.org/phpBB3/viewtopic.php?f = 7&t = 427 – lawlist