31 lines
809 B
Bash
Executable File
31 lines
809 B
Bash
Executable File
#!/bin/sh -e
|
|
# ex - archive extractor
|
|
# usage: ex <file>
|
|
for arg do
|
|
if test -r "$arg"; then
|
|
arg="$(realpath "$arg")"
|
|
name="$(basename "${arg%.*}")"
|
|
if test "$(ls -U | wc -l)" -gt 2; then
|
|
mkdir "$name"
|
|
cd "$name"
|
|
fi
|
|
case "$arg" in
|
|
*.tar.bz2) tar xjf "$arg" ;;
|
|
*.tar.*|*.tar) tar --extract --file "$arg";;
|
|
*.bz2) bunzip2 "$arg" ;;
|
|
*.rar) unrar x "$arg" ;;
|
|
*.gz) gunzip "$arg" ;;
|
|
*.tbz2) tar xjf "$arg" ;;
|
|
*.tgz) tar xzf "$arg" ;;
|
|
*.zip|*.jar) unzip "$arg" ;;
|
|
*.Z) uncompress "$arg";;
|
|
*.7z) 7z x "$arg" ;;
|
|
*.deb) ar x "$arg" ;;
|
|
*.zst) unzstd "$arg" ;;
|
|
*) echo "'$arg' cannot be extracted by ex" ;;
|
|
esac
|
|
else
|
|
echo "'$1' is not a readable file"
|
|
fi
|
|
done
|