mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-17 03:10:09 +00:00
fix(extract): extraction to directory for single-file .gz (#11852)
This commit is contained in:
parent
dfe2f04de7
commit
3f477e5da5
1 changed files with 8 additions and 8 deletions
|
@ -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
|
||||||
# - 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 file/folder (${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 file/folder 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 file/folder 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
|
||||||
|
|
Loading…
Reference in a new issue