The main documentation is availiable via --help and near the top of any bash
script files which sit next to this file.
-Files ending in -function are for sourcing then calling as a function. Files
-without -function are exactly the same except they are for calling as a script.
+The script file can be stripped of the last line and used as a function
+instead of a script.
Patches, bugs, and any feedback is very welcome via gitorious or email to
Ian Kelling <ian@iankelling.org>.
fi
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
- if [[ $(sudo -v) == Sorry* ]]; then
- echo error: need superuser priveledge for iso file
- return 1
- fi
super=sudo
fi
local temp_dir=$(mktemp -d)
- losetup -f
+ $super losetup -f
$super mount -o loop "$x" "$temp_dir"
local dir="${x%%.iso}"
mkdir "$dir"
- cp -av "$temp_dir"/* "$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
+ *) echo "I don't kno how to extract $x";;
+ esac
done
}
ex "$@"
+++ /dev/null
-#!/bin/bash
-# Copyright (C) 2014 Ian Kelling
-
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-
-# http://www.apache.org/licenses/LICENSE-2.0
-
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-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."
- if [[ $1 == --help ]]; then
- echo "$help"
- fi
- 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" ;;
- *.iso )
- if [[ $EUID != 0 ]]; then
- if [[ $(sudo -v) == Sorry* ]]; then
- echo error: need superuser priveledge for iso file
- return 1
- fi
- super=sudo
- fi
- local temp_dir=$(mktemp -d)
- losetup -f
- $super mount -o loop "$x" "$temp_dir"
- local dir="${x%%.iso}"
- mkdir "$dir"
- cp -av "$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
- done
-}