Created
November 24, 2011 07:59
-
-
Save justinabrahms/1390864 to your computer and use it in GitHub Desktop.
extract archives from eshell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun if-string-match-then-result (to-match pairs) | |
"Takes a string to match and a list of pairs, the first element | |
of the pairs is a regexp to test against the string, the second of | |
which is a return value if it matches." | |
(catch 'break | |
(dolist (val pairs) | |
(if (string-match-p (car val) to-match) | |
(progn | |
(throw 'break (cadr val))))) | |
(throw 'break nil))) | |
(defun eshell/extract (file) | |
(eshell-command-result (concat (if-string-match-then-result | |
file | |
'((".*\.tar.bz2" "tar xjf") | |
(".*\.tar.gz" "tar xzf") | |
(".*\.bz2" "bunzip2") | |
(".*\.rar" "unrar x") | |
(".*\.gz" "gunzip") | |
(".*\.tar" "tar xf") | |
(".*\.tbz2" "tar xjf") | |
(".*\.tgz" "tar xzf") | |
(".*\.zip" "unzip") | |
(".*\.Z" "uncompress") | |
(".*" "echo 'Could not extract the requested file:'"))) | |
" " file))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment