ext alias added and extract script -c option fixed
This commit is contained in:
parent
cb58970a09
commit
f83aab2aa7
2 changed files with 31 additions and 22 deletions
1
.scripts/ext
Symbolic link
1
.scripts/ext
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
extract
|
|
@ -1,36 +1,44 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
# A general, all-purpose extraction script.
|
# A general, all-purpose extraction script.
|
||||||
#
|
#
|
||||||
# Default behavior: Extract archive into new directory
|
# Default behavior: Extract archive into new directory
|
||||||
# Behavior with `-c` option: Extract contents into current directory
|
# Behavior with `-c` option: Extract contents into current directory
|
||||||
|
|
||||||
while getopts "hc" o; do case "${o}" in
|
while getopts "hc" o; do case "${o}" in
|
||||||
h) echo -e "Options:\n -c: Extract archive into current directory rather than a new one." && exit ;;
|
c) extracthere="True" ;;
|
||||||
c) dirpref="" && archive=${@:2} ;;
|
*) printf "Options:\\n -c: Extract archive into current directory rather than a new one.\\n" && exit ;;
|
||||||
esac done
|
esac done
|
||||||
|
|
||||||
[ -z ${dirpref+x} ] && dirpref="../" && archive="$@"
|
if [ -z "$extracthere" ]; then
|
||||||
|
archive="$(readlink -f "$*")" &&
|
||||||
|
directory=${archive%.*} &&
|
||||||
|
mkdir -p "$directory" &&
|
||||||
|
cd "$directory" || exit
|
||||||
|
else
|
||||||
|
archive="$(readlink -f "$(echo "$*" | cut -d' ' -f2)")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ "$archive" = "" ] && printf "Give archive to extract as argument.\\n" && exit
|
||||||
|
|
||||||
if [ -f "$archive" ] ; then
|
if [ -f "$archive" ] ; then
|
||||||
[[ "$dirpref" == "../" ]] && NAME=${archive%.*} && mkdir "$NAME" && cd "$NAME"
|
|
||||||
case "$archive" in
|
case "$archive" in
|
||||||
*.tar.bz2) tar xvjf "$dirpref""$archive" ;;
|
*.tar.bz2) tar xvjf "$archive" ;;
|
||||||
*.tar.gz) tar xvzf "$dirpref""$archive" ;;
|
*.tar.gz) tar xvzf "$archive" ;;
|
||||||
*.tar.xz) tar xvJf "$dirpref""$archive" ;;
|
*.tar.xz) tar xvJf "$archive" ;;
|
||||||
*.lzma) unlzma "$dirpref""$archive" ;;
|
*.lzma) unlzma "$archive" ;;
|
||||||
*.bz2) bunzip2 "$dirpref""$archive" ;;
|
*.bz2) bunzip2 "$archive" ;;
|
||||||
*.rar) unrar x -ad "$dirpref""$archive" ;;
|
*.rar) unrar x -ad "$archive" ;;
|
||||||
*.gz) gunzip "$dirpref""$archive" ;;
|
*.gz) gunzip "$archive" ;;
|
||||||
*.tar) tar xvf "$dirpref""$archive" ;;
|
*.tar) tar xvf "$archive" ;;
|
||||||
*.tbz2) tar xvjf "$dirpref""$archive" ;;
|
*.tbz2) tar xvjf "$archive" ;;
|
||||||
*.tgz) tar xvzf "$dirpref""$archive" ;;
|
*.tgz) tar xvzf "$archive" ;;
|
||||||
*.zip) unzip "$dirpref""$archive" ;;
|
*.zip) unzip "$archive" ;;
|
||||||
*.Z) uncompress "$dirpref""$archive" ;;
|
*.Z) uncompress "$archive" ;;
|
||||||
*.7z) 7z x "$dirpref""$archive" ;;
|
*.7z) 7z x "$archive" ;;
|
||||||
*.xz) unxz "$dirpref""$archive" ;;
|
*.xz) unxz "$archive" ;;
|
||||||
*.exe) cabextract "$dirpref""$archive" ;;
|
*.exe) cabextract "$archive" ;;
|
||||||
*) echo "extract: '$archive' - unknown archive method" ;;
|
*) printf "extract: '%s' - unknown archive method\\n" "$archive" ;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
echo "File \"$archive\" not found."
|
printf "File \"%s\" not found.\\n" "$archive"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue