bin/ex: automatically use subdirectory

This commit is contained in:
xeruf 2021-11-25 14:08:40 +01:00
parent 118f11386f
commit ebe7a6992b
1 changed files with 26 additions and 20 deletions

View File

@ -1,8 +1,14 @@
#!/bin/sh #!/bin/sh -e
# ex - archive extractor # ex - archive extractor
# usage: ex <file> # usage: ex <file>
for arg do for arg do
if test -r "$arg"; then 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 case "$arg" in
*.tar.bz2) tar xjf "$arg" ;; *.tar.bz2) tar xjf "$arg" ;;
*.tar.*|*.tar) tar --extract --file "$arg";; *.tar.*|*.tar) tar --extract --file "$arg";;