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
3a01d7df
Commit
3a01d7df
authored
May 21, 2023
by
Marc Cornellà
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(extract): fix extract dir naming conflicts
Fixes #11642
parent
bfeeda14
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
5 deletions
+15
-5
extract.plugin.zsh
plugins/extract/extract.plugin.zsh
+15
-5
No files found.
plugins/extract/extract.plugin.zsh
View file @
3a01d7df
...
@@ -27,12 +27,20 @@ EOF
...
@@ -27,12 +27,20 @@ EOF
fi
fi
local
success
=
0
local
success
=
0
local
extract_dir
=
"
${
1
:t:r
}
"
local
file
=
"
$1
"
full_path
=
"
${
1
:A
}
"
local
file
=
"
$1
"
full_path
=
"
${
1
:A
}
"
local
extract_dir
=
"
${
1
:t:r
}
"
# If there's a file or directory with the same name as the archive
# add a random string to the end of the extract directory
if
[[
-e
"
$extract_dir
"
]]
;
then
local
rnd
=
"
${
(L)
"
${$((
[
##36]$RANDOM*$RANDOM ))}":1:5}"
extract_dir
=
"
${
extract_dir
}
-
${
rnd
}
"
fi
# Create an extraction directory based on the file name
# Create an extraction directory based on the file name
command mkdir
-
p
"
$extract_dir
"
command mkdir
-
p
"
$extract_dir
"
builtin cd
-
q
"
$extract_dir
"
builtin cd
-
q
"
$extract_dir
"
echo
"extract: extracting to
$extract_dir
"
>&
2
case
"
${
file
:l
}
"
in
case
"
${
file
:l
}
"
in
(
*
.tar.gz|
*
.tgz
)
(
*
.tar.gz|
*
.tgz
)
...
@@ -107,11 +115,13 @@ EOF
...
@@ -107,11 +115,13 @@ EOF
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_dir==(
:
); tmp_dir=
"
${
tmp_dir
:t
}
"
command mv
-f
"
${
content
[1]
}
"
"
$tmp_dir
"
\
command mv
"
${
content
[1]
}
"
"
$tmp_dir
"
\
&& command rmdir
"
$extract_dir
"
\
&& command rmdir
"
$extract_dir
"
\
&&
command mv
-f
"
$tmp_dir
"
"
$extract_dir
"
&& command mv
"
$tmp_dir
"
"
$extract_dir
"
else
# Otherwise, if the extracted folder name already exists in the current
command mv
-f
"
${
content
[1]
}
"
.
\
# directory (because of a previous file / folder), keep the extract_dir
elif [[ ! -e
"
${
content
[1]
:t
}
"
]]; then
command mv
"
${
content
[1]
}
"
. \
&& command rmdir
"
$extract_dir
"
&& command rmdir
"
$extract_dir
"
fi
fi
elif [[
${#
content
}
-eq 0 ]]; then
elif [[
${#
content
}
-eq 0 ]]; 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