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
3f477e5d
Unverified
Commit
3f477e5d
authored
Aug 23, 2023
by
Marc Cornellà
Committed by
GitHub
Aug 23, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(extract): extraction to directory for single-file .gz (#11852)
parent
dfe2f04d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
extract.plugin.zsh
plugins/extract/extract.plugin.zsh
+8
-8
No files found.
plugins/extract/extract.plugin.zsh
View file @
3f477e5d
...
@@ -64,7 +64,7 @@ EOF
...
@@ -64,7 +64,7 @@ EOF
(
*
.tar.lz
)
((
$+
commands[lzip]
))
&&
tar
xvf
"
$full_path
"
;;
(
*
.tar.lz
)
((
$+
commands[lzip]
))
&&
tar
xvf
"
$full_path
"
;;
(
*
.tar.lz4
)
lz4
-c
-d
"
$full_path
"
|
tar
xvf -
;;
(
*
.tar.lz4
)
lz4
-c
-d
"
$full_path
"
|
tar
xvf -
;;
(
*
.tar.lrz
)
((
$+
commands[lrzuntar]
))
&&
lrzuntar
"
$full_path
"
;;
(
*
.tar.lrz
)
((
$+
commands[lrzuntar]
))
&&
lrzuntar
"
$full_path
"
;;
(
*
.gz
)
((
$+
commands[pigz]
))
&&
pigz
-
dk
"
$full_path
"
||
gunzip
-k
"
$full_path
"
;;
(
*
.gz
)
((
$+
commands[pigz]
))
&&
pigz
-
cdk
"
$full_path
"
>
"
${
file
:t:r
}
"
||
gunzip
-ck
"
$full_path
"
>
"
${
file
:t:r
}
"
;;
(
*
.bz2
)
bunzip2
"
$full_path
"
;;
(
*
.bz2
)
bunzip2
"
$full_path
"
;;
(
*
.xz
)
unxz
"
$full_path
"
;;
(
*
.xz
)
unxz
"
$full_path
"
;;
(
*
.lrz
)
((
$+
commands[lrunzip]
))
&&
lrunzip
"
$full_path
"
;;
(
*
.lrz
)
((
$+
commands[lrunzip]
))
&&
lrunzip
"
$full_path
"
;;
...
@@ -106,19 +106,19 @@ EOF
...
@@ -106,19 +106,19 @@ EOF
# - Y2
:
at most give 2 files
# - Y2
:
at most give 2 files
local -a content
local -a content
content=(
"
${
extract_dir
}
"
/*(DNY2))
content=(
"
${
extract_dir
}
"
/*(DNY2))
if [[
${#
content
}
-eq 1 && -
d
"
${
content
[1]
}
"
]]; then
if [[
${#
content
}
-eq 1 && -
e
"
${
content
[1]
}
"
]]; then
# The extracted folder (
${
content
[1]
}
) may have the same name as
$extract_dir
# The extracted f
ile/f
older (
${
content
[1]
}
) may have the same name as
$extract_dir
# If so, we need to rename it to avoid conflicts in a 3-step process
# If so, we need to rename it to avoid conflicts in a 3-step process
#
#
# 1. Move and rename the extracted folder to a temporary random name
# 1. Move and rename the extracted f
ile/f
older to a temporary random name
# 2. Delete the empty folder
# 2. Delete the empty folder
# 3. Rename the extracted folder to the original name
# 3. Rename the extracted f
ile/f
older to the original name
if [[
"
${
content
[1]
:t
}
"
==
"
$extract_dir
"
]]; then
if [[
"
${
content
[1]
:t
}
"
==
"
$extract_dir
"
]]; then
# =(
:
) gives /tmp/zsh<random>, with
:t
it gives zsh<random>
# =(
:
) gives /tmp/zsh<random>, with
:t
it gives zsh<random>
local tmp_
dir==(
:
); tmp_dir=
"
${
tmp_dir
:t
}
"
local tmp_
name==(
:
); tmp_name=
"
${
tmp_name
:t
}
"
command mv
"
${
content
[1]
}
"
"
$tmp_
dir
"
\
command mv
"
${
content
[1]
}
"
"
$tmp_
name
"
\
&& command rmdir
"
$extract_dir
"
\
&& command rmdir
"
$extract_dir
"
\
&& command mv
"
$tmp_
dir
"
"
$extract_dir
"
&& command mv
"
$tmp_
name
"
"
$extract_dir
"
# Otherwise, if the extracted folder name already exists in the current
# Otherwise, if the extracted folder name already exists in the current
# directory (because of a previous file / folder), keep the extract_dir
# directory (because of a previous file / folder), keep the extract_dir
elif [[ ! -e
"
${
content
[1]
:t
}
"
]]; then
elif [[ ! -e
"
${
content
[1]
:t
}
"
]]; then
...
...
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