0b32e4b25fa7f3215964281a8af4e3ff2bf4cd68

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

Message

style(extract): adopt main code style guide and refactor variables

Diff

This diff is truncated to protect this page.

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