2021-11-25 13:08:40 +00:00
|
|
|
#!/bin/sh -e
|
2020-11-16 11:29:31 +00:00
|
|
|
# ex - archive extractor
|
|
|
|
# usage: ex <file>
|
2021-12-02 22:31:48 +00:00
|
|
|
# depends: rewrite(in dotfiles)
|
2021-02-24 11:16:28 +00:00
|
|
|
for arg do
|
2021-11-25 13:08:40 +00:00
|
|
|
if test -r "$arg"; then
|
2021-12-02 11:50:18 +00:00
|
|
|
path="$(realpath "$arg")"
|
|
|
|
name="$(basename "${path%.*}")"
|
|
|
|
(
|
2021-11-25 13:08:40 +00:00
|
|
|
if test "$(ls -U | wc -l)" -gt 2; then
|
2021-12-02 11:50:18 +00:00
|
|
|
mkdir -p "$name"
|
2021-11-25 13:08:40 +00:00
|
|
|
cd "$name"
|
|
|
|
fi
|
2021-12-02 11:50:18 +00:00
|
|
|
echo "Extracting $arg into $PWD"
|
2021-11-25 13:08:40 +00:00
|
|
|
case "$arg" in
|
2021-12-02 11:50:18 +00:00
|
|
|
(*.tar.*|*.tar) tar --extract --file "$path";;
|
|
|
|
(*.tbz2) tar xjf "$path" ;;
|
|
|
|
(*.tgz) tar xzf "$path" ;;
|
|
|
|
(*.zip|*.jar) unzip "$path" | rewrite ;;
|
|
|
|
(*.gz) gunzip "$path" ;;
|
|
|
|
(*.bz2) bunzip2 "$path" ;;
|
|
|
|
(*.rar) unrar x "$path" ;;
|
|
|
|
(*.7z|*.z01) 7z x "$path" ;;
|
|
|
|
(*.deb) ar x "$path" ;;
|
|
|
|
(*.zst) unzstd "$path" ;;
|
|
|
|
(*.Z) uncompress "$path";;
|
|
|
|
(*) echo "'$arg' cannot be extracted by ex" >&2;;
|
2021-11-25 13:08:40 +00:00
|
|
|
esac
|
2021-12-02 11:50:18 +00:00
|
|
|
)
|
2021-11-25 13:08:40 +00:00
|
|
|
else
|
|
|
|
echo "'$1' is not a readable file"
|
|
|
|
fi
|
2021-02-24 11:16:28 +00:00
|
|
|
done
|