X-Git-Url: https://iankelling.org/git/?p=small-misc-bash;a=blobdiff_plain;f=ex;h=159297b10c421a7ba8867211767e2f2d9fc61c2e;hp=dcfb36910dd4c7616c430934bee6015ceefd6a01;hb=08759aa5b31bdd7a48f0ec161ec4c0b4235098dc;hpb=e409ebcdfd1ecc0aeae511d3a62caf6006b2643d diff --git a/ex b/ex index dcfb369..159297b 100755 --- a/ex +++ b/ex @@ -14,37 +14,52 @@ # limitations under the License. ex() { - local help="Usage: ex [--help] FILE ... -Extract each FILE according to its extension." + local help="Usage: ex [--help] FILE... +Extract many types of files + +Based on their extensions, +7z bz2 deb gz iso dsc rar rpm tar xz zip sfs & some combinations. +See source for exact file extensions. +Note: apt-get install dtrx will do the same for +most of these types, plus some more, I'm going +to try it out sometime." + if [[ $1 == --help ]]; then echo "$help" fi - local x + local x super for x in "$@"; do - case "$x" in - *.tar.bz2 | *.tbz2 ) tar xvjf "$x" ;; - *.tar.gz | *.tgz ) tar xvzf "$x" ;; - *.bz2 ) bunzip2 "$x" ;; - *.gz ) gunzip "$x" ;; - *.tar ) tar xvf "$x" ;; - *.zip ) unzip "$x" ;; - *.Z ) uncompress "$x" ;; - *.7z ) 7za x "$x" ;; - *.deb ) ar xv "$x" ;; - *.rpm ) rpm2cpio "$x" | cpio --extract --make-directories --verbose ;; - *.tar.xz ) tar Jxvf "$x" ;; + case "$x" in + *.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" ;; *.iso ) + local super + if [[ $EUID != 0 ]]; then + super=sudo + fi local temp_dir=$(mktemp -d) - losetup -f - s mount -o loop "$x" "$temp_dir" + $super losetup -f + $super mount -o loop "$x" "$temp_dir" local dir="${x%%.iso}" mkdir "$dir" - cp -av "$temp_dir"/* "$dir" - s umount "$temp_dir" + cp -a "$temp_dir"/* "$dir" + $super umount "$temp_dir" ;; *.r[0-9][0-9]|*.rar ) unrar x "$x" ;; - *) echo "I don't kno how to extract $x";; - esac + *.dsc) dpkg-source -x "$x" ;; + *.sfs) $super unsquashfs "$x" ;; + *) echo "I don't know how to extract $x";; + esac done } ex "$@"