X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=ex;h=cf04ee6f2f26e93d3ac5ec30b5030a39e7b55611;hb=f0fb727480e27b66697b300d4046e8148b5623aa;hp=775aba89dc69e23ffb7c77c518167c4228c9d1a7;hpb=36c6aae170a004b693104289119274e488bfc997;p=small-misc-bash diff --git a/ex b/ex index 775aba8..cf04ee6 100755 --- a/ex +++ b/ex @@ -15,27 +15,41 @@ ex() { local help="Usage: ex [--help] FILE... -Extract each FILE according to its extension. -7z bz2 deb gz iso rar rpm tar xz zip & variations. -See source for exact file extensions." +Extract many types of files + +Based on their extensions, +7z [tar.]bz2 deb [tar.]gz iso dsc rar rpm sfs tar xpi [tar.]xz zip Z. +See source for exact file extensions. +Note: dtrx (package & command) extracts most of these plus some others." + if [[ $1 == --help ]]; then echo "$help" fi local x super for x in "$@"; do case "$x" in + # tars first, so they are higher pri than non-tar extensions + *.tar ) tar xf "$x" ;; *.tar.bz2 | *.tbz2 ) tar xjf "$x" ;; *.tar.gz | *.tgz ) tar xzf "$x" ;; - *.bz2 ) bunzip2 "$x" ;; - *.gz ) gunzip "$x" ;; - *.tar ) tar xf "$x" ;; - *.zip ) unzip "$x" ;; - *.Z ) uncompress "$x" ;; - *.7z ) 7za x "$x" ;; - *.deb ) ar x "$x" ;; - *.rpm ) rpm2cpio "$x" | cpio --extract --make-directories ;; *.tar.xz ) tar Jxf "$x" ;; *.xz) xz -d "$x" ;; + *.7z ) 7za x "$x" ;; + *.bz2 ) bunzip2 "$x" ;; + *.deb ) + ar x "$x" + tmp=(data.tar.*) + case $tmp in + *.xz) tar xJf data.tar.xz ;; + *.gz) tar xzf data.tar.gz ;; + *) echo "error: could not find data.tar.*" >&2; exit 1 ;; + esac + tar xzf control.tar.gz + rm -f control.tar.gz + rm -f data.tar.* + ;; + *.dsc) dpkg-source -x "$x" ;; + *.gz ) gunzip "$x" ;; *.iso ) local super if [[ $EUID != 0 ]]; then @@ -49,9 +63,14 @@ See source for exact file extensions." cp -a "$temp_dir"/* "$dir" $super umount "$temp_dir" ;; + *.jar) jar xf "$x" ;; *.r[0-9][0-9]|*.rar ) unrar x "$x" ;; - *.dsc) dpkg-source -x "$x" ;; - *) echo "I don't kno how to extract $x";; + *.rpm ) rpm2cpio "$x" | cpio --extract --make-directories ;; + *.sfs) $super unsquashfs "$x" ;; + *.Z ) uncompress "$x" ;; + *.zip|*.xpi ) unzip "$x" ;; + + *) echo "I don't know how to extract $x";; esac done }