Skip to content

Instantly share code, notes, and snippets.

@KeenS
Created October 4, 2013 15:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KeenS/6828197 to your computer and use it in GitHub Desktop.
Save KeenS/6828197 to your computer and use it in GitHub Desktop.
A dired-mode extension to archive files marked. To use, mark files with `m` and then `T`. Notice that you can uncompress and/or expand wth `!` default command (`tar xzvf`).
(defun dired-tar (tarname files &optional arg)
"A dired-mode extension to archive files marked. With prefix argument, the tarball is gziped."
(interactive (let ((files (dired-get-marked-files)))
(list (read-string "Tarball name: " (concat (file-relative-name (car files)) ".tar.gz"))
files "P")))
(let ((tar (if arg
(if dired-guess-shell-gnutar
(concat dired-guess-shell-gnutar " zcf %s %s")
"tar cf - %2s | gzip > %1s")
"tar cf %s %s")))
(shell-command (format tar tarname (mapconcat 'file-relative-name files " ")))))
(add-hook 'dired-load-hook (lambda () (define-key dired-mode-map "T" 'dired-tar)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment