Skip to content

Instantly share code, notes, and snippets.

@justinabrahms
Created November 24, 2011 07:59
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 justinabrahms/1390864 to your computer and use it in GitHub Desktop.
Save justinabrahms/1390864 to your computer and use it in GitHub Desktop.
extract archives from eshell
(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