0b809c8dc5dd23a1720f9135516f0f9e7c98b5f1
- Author
- Marc Cornellà <hello@mcornella.com>
- Committer
- Marc Cornellà <hello@mcornella.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/extract/README.md b/plugins/extract/README.md
2index f2e6ad1d1cce34ce427bad276e68c841d76c67f8..44f0b05a1c35095da23b5d11e191b8c6c79f87b7 100644
3--- a/plugins/extract/README.md
4+++ b/plugins/extract/README.md
5@@ -21,6 +21,8 @@ plugins=(... extract)
6 | `apk` | Android app file |
7 | `aar` | Android library file |
8 | `bz2` | Bzip2 file |
9+| `cab` | Microsoft cabinet archive |
10+| `cpio` | Cpio archive |
11 | `deb` | Debian package |
12 | `ear` | Enterprise Application aRchive |
13 | `gz` | Gzip file |
14diff --git a/plugins/extract/_extract b/plugins/extract/_extract
15index 267c4d4e14cd2d0a95b186b5e3832ad9ef76a219..27b099c9e4efe741010947a887568d9733b0e8d6 100644
16--- a/plugins/extract/_extract
17+++ b/plugins/extract/_extract
18@@ -3,5 +3,5 @@
19
20 _arguments \
21 '(-r --remove)'{-r,--remove}'[Remove archive.]' \
22- "*::archive file:_files -g '(#i)*.(7z|Z|apk|aar|bz2|deb|ear|gz|ipa|ipsw|jar|lrz|lz4|lzma|rar|rpm|sublime-package|tar|tar.bz2|tar.gz|tar.lrz|tar.lz|tar.lz4|tar.xz|tar.zma|tar.zst|tbz|tbz2|tgz|tlz|txz|tzst|war|whl|xpi|xz|zip|zst)(-.)'" \
23+ "*::archive file:_files -g '(#i)*.(7z|Z|apk|aar|bz2|cab|cpio|deb|ear|gz|ipa|ipsw|jar|lrz|lz4|lzma|rar|rpm|sublime-package|tar|tar.bz2|tar.gz|tar.lrz|tar.lz|tar.lz4|tar.xz|tar.zma|tar.zst|tbz|tbz2|tgz|tlz|txz|tzst|war|whl|xpi|xz|zip|zst)(-.)'" \
24 && return 0
25diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh
26index e390e2dccaff9bc910b0e29f1a2f04dc106967ef..1112dd52f289ed34b3342750fca04ecb9d8d216f 100644
27--- a/plugins/extract/extract.plugin.zsh
28+++ b/plugins/extract/extract.plugin.zsh
29@@ -1,82 +1,85 @@
30 alias x=extract
31
32 extract() {
33- local remove_archive
34- local success
35- local extract_dir
36+ setopt localoptions noautopushd
37
38- if (( $# == 0 )); then
39- cat <<-'EOF' >&2
40- Usage: extract [-option] [file ...]
41+ if (( $# == 0 )); then
42+ cat >&2 <<'EOF'
43+Usage: extract [-option] [file ...]
44
45- Options:
46- -r, --remove Remove archive after unpacking.
47- EOF
48- fi
49+Options:
50+ -r, --remove Remove archive after unpacking.
51+EOF
52+ fi
53
54- remove_archive=1
55- if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then
56- remove_archive=0
57- shift
58- fi
59+ local remove_archive=1
60+ if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then
61+ remove_archive=0
62+ shift
63+ fi
64
65- while (( $# > 0 )); do
66- if [[ ! -f "$1" ]]; then
67- echo "extract: '$1' is not a valid file" >&2
68- shift
69- continue
70- fi
71+ local pwd="$PWD"
72+ while (( $# > 0 )); do
73+ if [[ ! -f "$1" ]]; then
74+ echo "extract: '$1' is not a valid file" >&2
75+ shift
76+ continue
77+ fi
78
79- success=0
80- extract_dir="${1:t:r}"
81- case "${1:l}" in
82- (*.tar.gz|*.tgz) (( $+commands[pigz] )) && { pigz -dc "$1" | tar xv } || tar zxvf "$1" ;;
83- (*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;;
84- (*.tar.xz|*.txz)
85- tar --xz --help &> /dev/null \
86- && tar --xz -xvf "$1" \
87- || xzcat "$1" | tar xvf - ;;
88- (*.tar.zma|*.tlz)
89- tar --lzma --help &> /dev/null \
90- && tar --lzma -xvf "$1" \
91- || lzcat "$1" | tar xvf - ;;
92- (*.tar.zst|*.tzst)
93- tar --zstd --help &> /dev/null \
94- && tar --zstd -xvf "$1" \
95- || zstdcat "$1" | tar xvf - ;;
96- (*.tar) tar xvf "$1" ;;
97- (*.tar.lz) (( $+commands[lzip] )) && tar xvf "$1" ;;
98- (*.tar.lz4) lz4 -c -d "$1" | tar xvf - ;;
99- (*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$1" ;;
100- (*.gz) (( $+commands[pigz] )) && pigz -dk "$1" || gunzip -k "$1" ;;
101- (*.bz2) bunzip2 "$1" ;;
102- (*.xz) unxz "$1" ;;
103- (*.lrz) (( $+commands[lrunzip] )) && lrunzip "$1" ;;
104- (*.lz4) lz4 -d "$1" ;;
105- (*.lzma) unlzma "$1" ;;
106- (*.z) uncompress "$1" ;;
107- (*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$1" -d $extract_dir ;;
108- (*.rar) unrar x -ad "$1" ;;
109- (*.rpm) mkdir "$extract_dir" && cd "$extract_dir" && rpm2cpio "../$1" | cpio --quiet -id && cd .. ;;
110- (*.7z) 7za x "$1" ;;
111- (*.deb)
112- mkdir -p "$extract_dir/control"
113- mkdir -p "$extract_dir/data"
114- cd "$extract_dir"; ar vx "../${1}" > /dev/null
115- cd control; tar xzvf ../control.tar.gz
116- cd ../data; extract ../data.tar.*
117- cd ..; rm *.tar.* debian-binary
118- cd ..
119- ;;
120- (*.zst) unzstd "$1" ;;
121- (*)
122- echo "extract: '$1' cannot be extracted" >&2
123- success=1
124- ;;
125- esac
126+ local success=0
127+ local extract_dir="${1:t:r}"
128+ local file="$1" full_path="${1:A}"