... | ... |
@@ -15,38 +15,3 @@ function take() { |
15 | 15 |
cd $1 |
16 | 16 |
} |
17 | 17 |
|
18 |
-function extract() { |
|
19 |
- unset REMOVE_ARCHIVE |
|
20 |
- |
|
21 |
- if test "$1" = "-r"; then |
|
22 |
- REMOVE=1 |
|
23 |
- shift |
|
24 |
- fi |
|
25 |
- if [[ -f $1 ]]; then |
|
26 |
- case $1 in |
|
27 |
- *.tar.bz2) tar xvjf $1;; |
|
28 |
- *.tar.gz) tar xvzf $1;; |
|
29 |
- *.tar.xz) tar xvJf $1;; |
|
30 |
- *.tar.lzma) tar --lzma -xvf $1;; |
|
31 |
- *.bz2) bunzip $1;; |
|
32 |
- *.rar) unrar x $1;; |
|
33 |
- *.gz) gunzip $1;; |
|
34 |
- *.tar) tar xvf $1;; |
|
35 |
- *.tbz2) tar xvjf $1;; |
|
36 |
- *.tgz) tar xvzf $1;; |
|
37 |
- *.zip) unzip $1;; |
|
38 |
- *.Z) uncompress $1;; |
|
39 |
- *.7z) 7z x $1;; |
|
40 |
- *) echo "'$1' cannot be extracted via >extract<";; |
|
41 |
- esac |
|
42 |
- |
|
43 |
- if [[ $REMOVE_ARCHIVE -eq 1 ]]; then |
|
44 |
- echo removing "$1"; |
|
45 |
- /bin/rm "$1"; |
|
46 |
- fi |
|
47 |
- |
|
48 |
- else |
|
49 |
- echo "'$1' is not a valid file" |
|
50 |
- fi |
|
51 |
-} |
|
52 |
- |
0 | 8 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,83 @@ |
0 |
+# ------------------------------------------------------------------------------ |
|
1 |
+# FILE: extract.plugin.zsh |
|
2 |
+# DESCRIPTION: oh-my-zsh plugin file. |
|
3 |
+# AUTHOR: Sorin Ionescu (sorin.ionescu@gmail.com) |
|
4 |
+# VERSION: 1.0.0 |
|
5 |
+# ------------------------------------------------------------------------------ |
|
6 |
+ |
|
7 |
+ |
|
8 |
+function extract() { |
|
9 |
+ local remove_archive |
|
10 |
+ local success |
|
11 |
+ local file_name |
|
12 |
+ local extract_dir |
|
13 |
+ |
|
14 |
+ if (( $# == 0 )); then |
|
15 |
+ echo "Usage: extract [-option] [file ...]" |
|
16 |
+ echo |
|
17 |
+ echo Options: |
|
18 |
+ echo " -r, --remove Remove archive." |
|
19 |
+ echo |
|
20 |
+ echo "Report bugs to <sorin.ionescu@gmail.com>." |
|
21 |
+ fi |
|
22 |
+ |
|
23 |
+ remove_archive=1 |
|
24 |
+ if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then |
|
25 |
+ remove_archive=0 |
|
26 |
+ shift |
|
27 |
+ fi |
|
28 |
+ |
|
29 |
+ while (( $# > 0 )); do |
|
30 |
+ if [[ ! -f "$1" ]]; then |
|
31 |
+ echo "extract: '$1' is not a valid file" 1>&2 |
|
32 |
+ shift |
|
33 |
+ continue |
|
34 |
+ fi |
|
35 |
+ |
|
36 |
+ success=0 |
|
37 |
+ file_name="$( basename "$1" )" |
|
38 |
+ extract_dir="$( echo "$file_name" | sed "s/\.${1##*.}//g" )" |
|
39 |
+ case "$1" in |
|
40 |
+ (*.tar.gz|*.tgz) tar xvzf "$1" ;; |
|
41 |
+ (*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;; |
|
42 |
+ (*.tar.xz|*.txz) tar xvJf "$1" ;; |
|
43 |
+ # (*.tar.xz|*.txz) xzcat "$1" | tar xvf - ;; |
|
44 |
+ (*.tar.lzma|*.tlz) tar --lzma -xvf "$1" ;; |
|
45 |
+ # (*.tar.lzma|*.tlz) lzcat "$1" | tar xvf - ;; |
|
46 |
+ (*.tar) tar xvf "$1" ;; |
|
47 |
+ (*.gz) gunzip "$1" ;; |
|
48 |
+ (*.bz2) bunzip2 "$1" ;; |
|
49 |
+ (*.xz) unxz "$1" ;; |
|
50 |
+ (*.lzma) unlzma "$1" ;; |
|
51 |
+ (*.Z) uncompress "$1" ;; |
|
52 |
+ (*.zip) unzip "$1" -d $extract_dir ;; |
|
53 |
+ (*.rar) unrar e -ad "$1" ;; |
|
54 |
+ (*.7z) 7za x "$1" ;; |
|
55 |
+ (*.deb) |
|
56 |
+ mkdir -p "$extract_dir/control" |
|
57 |
+ mkdir -p "$extract_dir/data" |
|
58 |
+ cd "$extract_dir"; ar vx "../${1}" > /dev/null |
|
59 |
+ cd control; tar xzvf ../control.tar.gz |
|
60 |
+ cd ../data; tar xzvf ../data.tar.gz |
|
61 |
+ cd ..; rm *.tar.gz debian-binary |
|
62 |
+ cd .. |
|
63 |
+ ;; |
|
64 |
+ (*) |
|
65 |
+ echo "extract: '$1' cannot be extracted" 1>&2 |
|
66 |
+ success=1 |
|
67 |
+ ;; |
|
68 |
+ esac |
|
69 |
+ |
|
70 |
+ (( success = $success > 0 ? $success : $? )) |
|
71 |
+ (( $success == 0 )) && (( $remove_archive == 0 )) && rm "$1" |
|
72 |
+ shift |
|
73 |
+ done |
|
74 |
+} |
|
75 |
+ |
|
76 |
+alias x=extract |
|
77 |
+ |
|
78 |
+# add extract completion function to path |
|
79 |
+fpath=($ZSH/plugins/extract $fpath) |
|
80 |
+autoload -U compinit |
|
81 |
+compinit -i |
|
82 |
+ |