75405b7b0ae03a1fdf2fdb172d2a50cd5f570162

Author
Marc Cornellà <hello@mcornella.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(extract): always extract files into its own folder (#11596)

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh
  2index 7b7a2fa4fc82e00f75aff2920ff3696cd005a357..c416f49ce3a6c293c2b1a6544b78833a9d73f6dc 100644
  3--- a/plugins/extract/extract.plugin.zsh
  4+++ b/plugins/extract/extract.plugin.zsh
  5@@ -29,61 +29,79 @@ EOF
  6     local success=0
  7     local extract_dir="${1:t:r}"
  8     local file="$1" full_path="${1:A}"
  9+
 10+    # Create an extraction directory based on the file name
 11+    command mkdir -p "$extract_dir"
 12+    builtin cd -q "$extract_dir"
 13+
 14     case "${file:l}" in
 15       (*.tar.gz|*.tgz)
 16-        (( $+commands[pigz] )) && { tar -I pigz -xvf "$file" } || tar zxvf "$file" ;;
 17+        (( $+commands[pigz] )) && { tar -I pigz -xvf "$full_path" } || tar zxvf "$full_path" ;;
 18       (*.tar.bz2|*.tbz|*.tbz2)
 19-        (( $+commands[pbzip2] )) && { tar -I pbzip2 -xvf "$file" } || tar xvjf "$file" ;;
 20+        (( $+commands[pbzip2] )) && { tar -I pbzip2 -xvf "$full_path" } || tar xvjf "$full_path" ;;
 21       (*.tar.xz|*.txz)
 22-        (( $+commands[pixz] )) && { tar -I pixz -xvf "$file" } || {
 23+        (( $+commands[pixz] )) && { tar -I pixz -xvf "$full_path" } || {
 24         tar --xz --help &> /dev/null \
 25-        && tar --xz -xvf "$file" \
 26-        || xzcat "$file" | tar xvf - } ;;
 27+        && tar --xz -xvf "$full_path" \
 28+        || xzcat "$full_path" | tar xvf - } ;;
 29       (*.tar.zma|*.tlz)
 30         tar --lzma --help &> /dev/null \
 31-        && tar --lzma -xvf "$file" \
 32-        || lzcat "$file" | tar xvf - ;;
 33+        && tar --lzma -xvf "$full_path" \
 34+        || lzcat "$full_path" | tar xvf - ;;
 35       (*.tar.zst|*.tzst)
 36         tar --zstd --help &> /dev/null \
 37-        && tar --zstd -xvf "$file" \
 38-        || zstdcat "$file" | tar xvf - ;;
 39-      (*.tar) tar xvf "$file" ;;
 40-      (*.tar.lz) (( $+commands[lzip] )) && tar xvf "$file" ;;
 41-      (*.tar.lz4) lz4 -c -d "$file" | tar xvf - ;;
 42-      (*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$file" ;;
 43-      (*.gz) (( $+commands[pigz] )) && pigz -dk "$file" || gunzip -k "$file" ;;
 44-      (*.bz2) bunzip2 "$file" ;;
 45-      (*.xz) unxz "$file" ;;
 46-      (*.lrz) (( $+commands[lrunzip] )) && lrunzip "$file" ;;
 47-      (*.lz4) lz4 -d "$file" ;;
 48-      (*.lzma) unlzma "$file" ;;
 49-      (*.z) uncompress "$file" ;;
 50-      (*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$file" -d "$extract_dir" ;;
 51-      (*.rar) unrar x -ad "$file" ;;
 52+        && tar --zstd -xvf "$full_path" \
 53+        || zstdcat "$full_path" | tar xvf - ;;
 54+      (*.tar) tar xvf "$full_path" ;;
 55+      (*.tar.lz) (( $+commands[lzip] )) && tar xvf "$full_path" ;;
 56+      (*.tar.lz4) lz4 -c -d "$full_path" | tar xvf - ;;
 57+      (*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$full_path" ;;
 58+      (*.gz) (( $+commands[pigz] )) && pigz -dk "$full_path" || gunzip -k "$full_path" ;;
 59+      (*.bz2) bunzip2 "$full_path" ;;
 60+      (*.xz) unxz "$full_path" ;;
 61+      (*.lrz) (( $+commands[lrunzip] )) && lrunzip "$full_path" ;;
 62+      (*.lz4) lz4 -d "$full_path" ;;
 63+      (*.lzma) unlzma "$full_path" ;;
 64+      (*.z) uncompress "$full_path" ;;
 65+      (*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$full_path" ;;
 66+      (*.rar) unrar x -ad "$full_path" ;;
 67       (*.rpm)
 68-        command mkdir -p "$extract_dir" && builtin cd -q "$extract_dir" \
 69-        && rpm2cpio "$full_path" | cpio --quiet -id ;;
 70-      (*.7z) 7za x "$file" ;;
 71+        rpm2cpio "$full_path" | cpio --quiet -id ;;
 72+      (*.7z) 7za x "$full_path" ;;
 73       (*.deb)
 74-        command mkdir -p "$extract_dir/control" "$extract_dir/data"
 75-        builtin cd -q "$extract_dir"; ar vx "$full_path" > /dev/null
 76+        command mkdir -p "control" "data"
 77+        ar vx "$full_path" > /dev/null
 78         builtin cd -q control; extract ../control.tar.*
 79         builtin cd -q ../data; extract ../data.tar.*
 80         builtin cd -q ..; command rm *.tar.* debian-binary ;;
 81-      (*.zst) unzstd "$file" ;;
 82-      (*.cab) cabextract -d "$extract_dir" "$file" ;;
 83-      (*.cpio|*.obscpio) cpio -idmvF "$file" ;;
 84-      (*.zpaq) zpaq x "$file" ;;
 85+      (*.zst) unzstd "$full_path" ;;
 86+      (*.cab) cabextract "$full_path" ;;
 87+      (*.cpio|*.obscpio) cpio -idmvF "$full_path" ;;
 88+      (*.zpaq) zpaq x "$full_path" ;;
 89       (*)
 90         echo "extract: '$file' cannot be extracted" >&2
 91         success=1 ;;
 92     esac
 93 
 94     (( success = success > 0 ? success : $? ))
 95-    (( success == 0 && remove_archive == 0 )) && rm "$full_path"
 96+    (( success == 0 && remove_archive == 0 )) && command rm "$full_path"
 97     shift
 98 
 99-    # Go back to original working directory in case we ran cd previously
100+    # Go back to original working directory
101+    # and remove extraction directory if there was an error
102     builtin cd -q "$pwd"
103+    (( success > 0 )) && command rm -r "$extract_dir"
104+