1159aa14fa810b4e7f0a12146988daa5567dab5a
- Author
- Marc Cornellà <marc.cornella@live.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/extract/README.md b/plugins/extract/README.md
2new file mode 100644
3index 0000000000000000000000000000000000000000..c6bdd36dd6c3cd2d6920103ca709dab17e47d340
4--- /dev/null
5+++ b/plugins/extract/README.md
6@@ -0,0 +1,46 @@
7+# extract plugin
8+
9+This plugin defines a function called `extract` that extracts the archive file
10+you pass it, and it supports a wide variety of archive filetypes.
11+
12+This way you don't have to know what specific command extracts a file, you just
13+do `extract <filename>` and the function takes care of the rest.
14+
15+To use it, add `extract` to the plugins array in your zshrc file:
16+
17+```zsh
18+plugins=(... extract)
19+```
20+
21+## Supported file extensions
22+
23+| Extension | Description |
24+|:------------------|:-------------------------------------|
25+| `7z` | 7zip file |
26+| `Z` | Z archive (LZW) |
27+| `apk` | Android app file |
28+| `bz2` | Bzip2 file |
29+| `deb` | Debian package |
30+| `gz` | Gzip file |
31+| `ipsw` | iOS firmware file |
32+| `jar` | Java Archive |
33+| `lzma` | LZMA archive |
34+| `rar` | WinRAR archive |
35+| `sublime-package` | Sublime Text package |
36+| `tar` | Tarball |
37+| `tar.bz2` | Tarball with bzip2 compression |
38+| `tar.gz` | Tarball with gzip compression |
39+| `tar.xz` | Tarball with lzma2 compression |
40+| `tar.zma` | Tarball with lzma compression |
41+| `tbz` | Tarball with bzip compression |
42+| `tbz2` | Tarball with bzip2 compression |
43+| `tgz` | Tarball with gzip compression |
44+| `tlz` | Tarball with lzma compression |
45+| `txz` | Tarball with lzma2 compression |
46+| `war` | Web Application archive (Java-based) |
47+| `xpi` | Mozilla XPI module file |
48+| `xz` | LZMA2 archive |
49+| `zip` | Zip archive |
50+
51+See [list of archive formats](https://en.wikipedia.org/wiki/List_of_archive_formats) for
52+more information regarding archive formats.
53diff --git a/plugins/extract/_extract b/plugins/extract/_extract
54index 387b344bc8e735c0966b4a02c2fee1caeb8b50d0..172425d2c6e2ceb4efe7a2f141c3680b2d33fe2f 100644
55--- a/plugins/extract/_extract
56+++ b/plugins/extract/_extract
57@@ -3,6 +3,5 @@
58
59 _arguments \
60 '(-r --remove)'{-r,--remove}'[Remove archive.]' \
61- "*::archive file:_files -g '(#i)*.(tar|tgz|tbz|tbz2|txz|tlz|gz|bz2|xz|lzma|Z|zip|ipsw|rar|7z|deb)(-.)'" && return 0
62-
63-
64+ "*::archive file:_files -g '(#i)*.(7z|Z|apk|bz2|deb|gz|ipsw|jar|lzma|rar|sublime-package|tar|tar.bz2|tar.gz|tar.xz|tar.zma|tbz|tbz2|tgz|tlz|txz|war|xpi|xz|zip)(-.)'" \
65+ && return 0
66diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh
67index 5d0809e9ad4c1c444b542460e5351f9416be9c72..c524bf8f56142edc289fc9c3f0af2e8ab9947e36 100644
68--- a/plugins/extract/extract.plugin.zsh
69+++ b/plugins/extract/extract.plugin.zsh
70@@ -1,80 +1,71 @@
71-# ------------------------------------------------------------------------------
72-# FILE: extract.plugin.zsh
73-# DESCRIPTION: oh-my-zsh plugin file.
74-# AUTHOR: Sorin Ionescu (sorin.ionescu@gmail.com)
75-# VERSION: 1.0.1
76-# ------------------------------------------------------------------------------
77+alias x=extract
78
79+extract() {
80+ local remove_archive
81+ local success
82+ local extract_dir
83
84-function extract() {
85- local remove_archive
86- local success
87- local file_name
88- local extract_dir
89+ if (( $# == 0 )); then
90+ cat <<-'EOF' >&2
91+ Usage: extract [-option] [file ...]
92
93- if (( $# == 0 )); then
94- echo "Usage: extract [-option] [file ...]"
95- echo
96- echo Options:
97- echo " -r, --remove Remove archive."
98- echo
99- echo "Report bugs to <sorin.ionescu@gmail.com>."
100- fi
101+ Options:
102+ -r, --remove Remove archive.
103+ EOF
104+ fi
105
106- remove_archive=1
107- if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then
108- remove_archive=0
109- shift
110- fi
111+ remove_archive=1
112+ if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then
113+ remove_archive=0
114+ shift
115+ fi
116
117- while (( $# > 0 )); do
118- if [[ ! -f "$1" ]]; then
119- echo "extract: '$1' is not a valid file" 1>&2
120- shift
121- continue
122- fi
123+ while (( $# > 0 )); do
124+ if [[ ! -f "$1" ]]; then
125+ echo "extract: '$1' is not a valid file" >&2
126+ shift
127+ continue
128+ fi
129
130- success=0
131- file_name="$( basename "$1" )"
132- extract_dir="$( echo "$file_name" | sed "s/\.${1##*.}//g" )"
133- case "$1" in
134- (*.tar.gz|*.tgz) [ -z $commands[pigz] ] && tar zxvf "$1" || pigz -dc "$1" | tar xv ;;
135- (*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;;
136- (*.tar.xz|*.txz) tar --xz --help &> /dev/null \
137- && tar --xz -xvf "$1" \
138- || xzcat "$1" | tar xvf - ;;
139- (*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \
140- && tar --lzma -xvf "$1" \
141- || lzcat "$1" | tar xvf - ;;
142- (*.tar) tar xvf "$1" ;;
143- (*.gz) [ -z $commands[pigz] ] && gunzip "$1" || pigz -d "$1" ;;
144- (*.bz2) bunzip2 "$1" ;;
145- (*.xz) unxz "$1" ;;
146- (*.lzma) unlzma "$1" ;;
147- (*.Z) uncompress "$1" ;;
148- (*.zip|*.war|*.jar|*.sublime-package|*.ipsw|*.xpi|*.apk) unzip "$1" -d $extract_dir ;;
149- (*.rar) unrar x -ad "$1" ;;
150- (*.7z) 7za x "$1" ;;
151- (*.deb)
152- mkdir -p "$extract_dir/control"
153- mkdir -p "$extract_dir/data"
154- cd "$extract_dir"; ar vx "../${1}" > /dev/null
155- cd control; tar xzvf ../control.tar.gz
156- cd ../data; tar xzvf ../data.tar.gz
157- cd ..; rm *.tar.gz debian-binary
158- cd ..
159- ;;
160- (*)
161- echo "extract: '$1' cannot be extracted" 1>&2
162- success=1
163- ;;
164- esac
165+ success=0
166+ extract_dir="${1:t:r}"
167+ case "$1" in
168+ (*.tar.gz|*.tgz) (( $+commands[pigz] )) && { pigz -dc "$1" | tar xv } || tar zxvf "$1" ;;
169+ (*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;;