X-Git-Url: https://ruderich.org/simon/gitweb/?p=config%2Fdotfiles.git;a=blobdiff_plain;f=shell%2Fzsh%2Ffunctions%2Fextract;fp=shell%2Fzsh%2Ffunctions%2Fextract;h=5a73454096ba179a2df770fd9ab00b210b4a834a;hp=0000000000000000000000000000000000000000;hb=29fe133e2b4ca2a25342fa9a4c3e661bc38895f2;hpb=3e17e82d591782b4750382b00c5bf6ee96eddedf diff --git a/shell/zsh/functions/extract b/shell/zsh/functions/extract new file mode 100644 index 0000000..5a73454 --- /dev/null +++ b/shell/zsh/functions/extract @@ -0,0 +1,41 @@ +# Author: Copyright © 2005 Eric P. Mangold - teratorn (-at-) gmail (-dot) com +# License: MIT. http://www.opensource.org/licenses/mit-license.html +# http://zshwiki.org/home/examples/functions + +local old_dirs current_dirs lower +lower=${(L)1} +old_dirs=( *(N/) ) +if [[ $lower == *.tar.gz || $lower == *.tgz ]]; then + tar zxfv $1 +elif [[ $lower == *.gz ]]; then + gunzip $1 +elif [[ $lower == *.tar.bz2 || $lower == *.tbz ]]; then + bunzip2 -c $1 | tar xfv - +elif [[ $lower == *.bz2 ]]; then + bunzip2 $1 +elif [[ $lower == *.zip ]]; then + unzip $1 +elif [[ $lower == *.rar ]]; then + unrar e $1 +elif [[ $lower == *.tar ]]; then + tar xfv $1 +elif [[ $lower == *.lha ]]; then + lha e $1 +else + print "Unknown archive type: $1" + return 1 +fi +# Change in to the newly created directory, and +# list the directory contents, if there is one. +current_dirs=( *(N/) ) +for i in {1..${#current_dirs}}; do + if [[ $current_dirs[$i] != $old_dirs[$i] ]]; then + cd $current_dirs[$i] + ls + break + fi +done + +#compdef '_files -g "*.gz *.tgz *.bz2 *.tbz *.zip *.rar *.tar *.lha"' extract_archive + +# vim: ft=zsh