diff options
author | Marc Cornellà <hello@mcornella.com> | 2023-08-23 13:25:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-23 13:25:33 +0200 |
commit | 3f477e5da5ee42356f103d2c5cdd478d23bf9f03 (patch) | |
tree | d751aa10972475526d798f2ef81da26df3d58032 /plugins | |
parent | dfe2f04de7e839ae0a9757c37a26b9d8710aa372 (diff) | |
download | zsh-3f477e5da5ee42356f103d2c5cdd478d23bf9f03.tar.gz zsh-3f477e5da5ee42356f103d2c5cdd478d23bf9f03.tar.bz2 zsh-3f477e5da5ee42356f103d2c5cdd478d23bf9f03.zip |
fix(extract): extraction to directory for single-file .gz (#11852)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/extract/extract.plugin.zsh | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh index b7a823c9f..513950f33 100644 --- a/plugins/extract/extract.plugin.zsh +++ b/plugins/extract/extract.plugin.zsh @@ -64,7 +64,7 @@ EOF (*.tar.lz) (( $+commands[lzip] )) && tar xvf "$full_path" ;; (*.tar.lz4) lz4 -c -d "$full_path" | tar xvf - ;; (*.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" ;; (*.xz) unxz "$full_path" ;; (*.lrz) (( $+commands[lrunzip] )) && lrunzip "$full_path" ;; @@ -106,19 +106,19 @@ EOF # - Y2: at most give 2 files local -a content content=("${extract_dir}"/*(DNY2)) - if [[ ${#content} -eq 1 && -d "${content[1]}" ]]; then - # The extracted folder (${content[1]}) may have the same name as $extract_dir + if [[ ${#content} -eq 1 && -e "${content[1]}" ]]; then + # 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 # - # 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 - # 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 # =(:) gives /tmp/zsh<random>, with :t it gives zsh<random> - local tmp_dir==(:); tmp_dir="${tmp_dir:t}" - command mv "${content[1]}" "$tmp_dir" \ + local tmp_name==(:); tmp_name="${tmp_name:t}" + command mv "${content[1]}" "$tmp_name" \ && 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 # directory (because of a previous file / folder), keep the extract_dir elif [[ ! -e "${content[1]:t}" ]]; then |