]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - zsh/functions/extract
5a73454096ba179a2df770fd9ab00b210b4a834a
[config/dotfiles.git] / zsh / functions / extract
1 # Author: Copyright © 2005 Eric P. Mangold - teratorn (-at-) gmail (-dot) com
2 # License: MIT. http://www.opensource.org/licenses/mit-license.html
3 # http://zshwiki.org/home/examples/functions
4
5 local old_dirs current_dirs lower
6 lower=${(L)1}
7 old_dirs=( *(N/) )
8 if [[ $lower == *.tar.gz || $lower == *.tgz ]]; then
9     tar zxfv $1
10 elif [[ $lower == *.gz ]]; then
11     gunzip $1
12 elif [[ $lower == *.tar.bz2 || $lower == *.tbz ]]; then
13     bunzip2 -c $1 | tar xfv -
14 elif [[ $lower == *.bz2 ]]; then
15     bunzip2 $1
16 elif [[ $lower == *.zip ]]; then
17     unzip $1
18 elif [[ $lower == *.rar ]]; then
19     unrar e $1
20 elif [[ $lower == *.tar ]]; then
21     tar xfv $1
22 elif [[ $lower == *.lha ]]; then
23     lha e $1
24 else
25     print "Unknown archive type: $1"
26     return 1
27 fi
28 # Change in to the newly created directory, and
29 # list the directory contents, if there is one.
30 current_dirs=( *(N/) )
31 for i in {1..${#current_dirs}}; do
32     if [[ $current_dirs[$i] != $old_dirs[$i] ]]; then
33         cd $current_dirs[$i]
34         ls
35         break
36     fi
37 done
38
39 #compdef '_files -g "*.gz *.tgz *.bz2 *.tbz *.zip *.rar *.tar *.lha"' extract_archive
40
41 # vim: ft=zsh