Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
75405b7b
Unverified
Commit
75405b7b
authored
Apr 02, 2023
by
Marc Cornellà
Committed by
GitHub
Apr 02, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(extract): always extract files into its own folder (#11596)
parent
f7d903f3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
33 deletions
+51
-33
extract.plugin.zsh
plugins/extract/extract.plugin.zsh
+51
-33
No files found.
plugins/extract/extract.plugin.zsh
View file @
75405b7b
...
...
@@ -29,61 +29,79 @@ EOF
local
success
=
0
local
extract_dir
=
"
${
1
:t:r
}
"
local
file
=
"
$1
"
full_path
=
"
${
1
:A
}
"
# Create an extraction directory based on the file name
command mkdir
-p
"
$extract_dir
"
builtin cd
-q
"
$extract_dir
"
case
"
${
file
:l
}
"
in
(
*
.tar.gz|
*
.tgz
)
((
$+
commands[pigz]
))
&&
{
tar
-I
pigz
-xvf
"
$f
ile
"
}
||
tar
zxvf
"
$file
"
;;
((
$+
commands[pigz]
))
&&
{
tar
-I
pigz
-xvf
"
$f
ull_path
"
}
||
tar
zxvf
"
$full_path
"
;;
(
*
.tar.bz2|
*
.tbz|
*
.tbz2
)
((
$+
commands[pbzip2]
))
&&
{
tar
-I
pbzip2
-xvf
"
$f
ile
"
}
||
tar
xvjf
"
$file
"
;;
((
$+
commands[pbzip2]
))
&&
{
tar
-I
pbzip2
-xvf
"
$f
ull_path
"
}
||
tar
xvjf
"
$full_path
"
;;
(
*
.tar.xz|
*
.txz
)
((
$+
commands[pixz]
))
&&
{
tar
-I
pixz
-xvf
"
$f
ile
"
}
||
{
((
$+
commands[pixz]
))
&&
{
tar
-I
pixz
-xvf
"
$f
ull_path
"
}
||
{
tar
--xz
--help
&> /dev/null
\
&&
tar
--xz
-xvf
"
$f
ile
"
\
||
xzcat
"
$f
ile
"
|
tar
xvf -
}
;;
&&
tar
--xz
-xvf
"
$f
ull_path
"
\
||
xzcat
"
$f
ull_path
"
|
tar
xvf -
}
;;
(
*
.tar.zma|
*
.tlz
)
tar
--lzma
--help
&> /dev/null
\
&&
tar
--lzma
-xvf
"
$f
ile
"
\
||
lzcat
"
$f
ile
"
|
tar
xvf -
;;
&&
tar
--lzma
-xvf
"
$f
ull_path
"
\
||
lzcat
"
$f
ull_path
"
|
tar
xvf -
;;
(
*
.tar.zst|
*
.tzst
)
tar
--zstd
--help
&> /dev/null
\
&&
tar
--zstd
-xvf
"
$f
ile
"
\
||
zstdcat
"
$f
ile
"
|
tar
xvf -
;;
(
*
.tar
)
tar
xvf
"
$f
ile
"
;;
(
*
.tar.lz
)
((
$+
commands[lzip]
))
&&
tar
xvf
"
$f
ile
"
;;
(
*
.tar.lz4
)
lz4
-c
-d
"
$f
ile
"
|
tar
xvf -
;;
(
*
.tar.lrz
)
((
$+
commands[lrzuntar]
))
&&
lrzuntar
"
$f
ile
"
;;
(
*
.gz
)
((
$+
commands[pigz]
))
&&
pigz
-dk
"
$f
ile
"
||
gunzip
-k
"
$file
"
;;
(
*
.bz2
)
bunzip2
"
$f
ile
"
;;
(
*
.xz
)
unxz
"
$f
ile
"
;;
(
*
.lrz
)
((
$+
commands[lrunzip]
))
&&
lrunzip
"
$f
ile
"
;;
(
*
.lz4
)
lz4
-d
"
$f
ile
"
;;
(
*
.lzma
)
unlzma
"
$f
ile
"
;;
(
*
.z
)
uncompress
"
$f
ile
"
;;
(
*
.zip|
*
.war|
*
.jar|
*
.ear|
*
.sublime-package|
*
.ipa|
*
.ipsw|
*
.xpi|
*
.apk|
*
.aar|
*
.whl
)
unzip
"
$f
ile
"
-d
"
$extract_dir
"
;;
(
*
.rar
)
unrar x
-ad
"
$f
ile
"
;;
&&
tar
--zstd
-xvf
"
$f
ull_path
"
\
||
zstdcat
"
$f
ull_path
"
|
tar
xvf -
;;
(
*
.tar
)
tar
xvf
"
$f
ull_path
"
;;
(
*
.tar.lz
)
((
$+
commands[lzip]
))
&&
tar
xvf
"
$f
ull_path
"
;;
(
*
.tar.lz4
)
lz4
-c
-d
"
$f
ull_path
"
|
tar
xvf -
;;
(
*
.tar.lrz
)
((
$+
commands[lrzuntar]
))
&&
lrzuntar
"
$f
ull_path
"
;;
(
*
.gz
)
((
$+
commands[pigz]
))
&&
pigz
-dk
"
$f
ull_path
"
||
gunzip
-k
"
$full_path
"
;;
(
*
.bz2
)
bunzip2
"
$f
ull_path
"
;;
(
*
.xz
)
unxz
"
$f
ull_path
"
;;
(
*
.lrz
)
((
$+
commands[lrunzip]
))
&&
lrunzip
"
$f
ull_path
"
;;
(
*
.lz4
)
lz4
-d
"
$f
ull_path
"
;;
(
*
.lzma
)
unlzma
"
$f
ull_path
"
;;
(
*
.z
)
uncompress
"
$f
ull_path
"
;;
(
*
.zip|
*
.war|
*
.jar|
*
.ear|
*
.sublime-package|
*
.ipa|
*
.ipsw|
*
.xpi|
*
.apk|
*
.aar|
*
.whl
)
unzip
"
$f
ull_path
"
;;
(
*
.rar
)
unrar x
-ad
"
$f
ull_path
"
;;
(
*
.rpm
)
command mkdir
-p
"
$extract_dir
"
&&
builtin cd
-q
"
$extract_dir
"
\
&&
rpm2cpio
"
$full_path
"
| cpio
--quiet
-id
;;
(
*
.7z
)
7za x
"
$file
"
;;
rpm2cpio
"
$full_path
"
| cpio
--quiet
-id
;;
(
*
.7z
)
7za x
"
$full_path
"
;;
(
*
.deb
)
command mkdir
-p
"
$extract_dir
/control"
"
$extract_dir
/
data"
builtin cd
-q
"
$extract_dir
"
;
ar vx
"
$full_path
"
>
/dev/null
command mkdir
-p
"
control"
"
data"
ar vx
"
$full_path
"
>
/dev/null
builtin cd
-q
control
;
extract ../control.tar.
*
builtin cd
-q
../data
;
extract ../data.tar.
*
builtin cd
-q
..
;
command rm
*
.tar.
*
debian-binary
;;
(
*
.zst
)
unzstd
"
$f
ile
"
;;
(
*
.cab
)
cabextract
-d
"
$extract_dir
"
"
$file
"
;;
(
*
.cpio|
*
.obscpio
)
cpio
-idmvF
"
$f
ile
"
;;
(
*
.zpaq
)
zpaq x
"
$f
ile
"
;;
(
*
.zst
)
unzstd
"
$f
ull_path
"
;;
(
*
.cab
)
cabextract
"
$full_path
"
;;
(
*
.cpio|
*
.obscpio
)
cpio
-idmvF
"
$f
ull_path
"
;;
(
*
.zpaq
)
zpaq x
"
$f
ull_path
"
;;
(
*
)
echo
"extract: '
$file
' cannot be extracted"
>
&2
success
=
1
;;
esac
((
success
=
success
>
0 ? success :
$?
))
((
success
==
0
&&
remove_archive
==
0
))
&&
rm
"
$full_path
"
((
success
==
0
&&
remove_archive
==
0
))
&&
command
rm
"
$full_path
"
shift
# Go back to original working directory in case we ran cd previously
# Go back to original working directory
# and remove extraction directory if there was an error
builtin cd
-q
"
$pwd
"
((
success
>
0
))
&&
command rm
-r
"
$extract_dir
"
# If content of extract dir is a single directory, move its contents up
# Glob flags:
# - D: include files starting with .
# - N: no error if directory is empty
# - Y2: at most give 2 files
local
-a
content
content
=(
"
${
extract_dir
}
"
/
*
(
DNY2
))
if
[[
${#
content
}
-eq
1
&&
-d
"
${
content
[1]
}
"
]]
;
then
command mv
-f
"
${
content
[1]
}
"
.
command rmdir
"
$extract_dir
"
fi
done
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment