bin/ex: automatically use subdirectory
This commit is contained in:
parent
118f11386f
commit
ebe7a6992b
|
@ -1,24 +1,30 @@
|
|||
#!/bin/sh
|
||||
#!/bin/sh -e
|
||||
# ex - archive extractor
|
||||
# usage: ex <file>
|
||||
for arg do
|
||||
if test -r "$arg"; then
|
||||
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
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue