`extract` multiple files each to their own directory

master
Jordan Atwood 2 years ago
parent b6438029e7
commit 3e3a2e391b
Signed by: nightfirecat
GPG Key ID: 615A619C2D73A6DF
  1. 45
      src/.bashrc

@ -530,27 +530,30 @@ function ff {
# simple extract script # simple extract script
# source: http://tldp.org/LDP/abs/html/sample-bashrc.html # source: http://tldp.org/LDP/abs/html/sample-bashrc.html
function extract { function extract {
if [ -f "$1" ]; then for arg in "$@"; do
case "$1" in if [ -f "$arg" ]; then
*.tar.bz2) tar xvjf "$1" ;; dir="${arg%%.*}"
*.tar.gz) tar xvzf "$1" ;; mkdir "$dir"
*.tar.xz) tar xJf "$1" ;; case "$arg" in
*.bz2) bunzip2 "$1" ;; *.tar.bz2) tar xvjf "$arg" -C "$dir" ;;
*.rar) unrar x "$1" ;; *.tar.gz) tar xvzf "$arg" -C "$dir" ;;
*.gz) gunzip "$1" ;; *.tar.xz) tar xJf "$arg" -C "$dir" ;;
*.tar) tar xvf "$1" ;; *.rar) unrar x "$arg" "$dir" ;;
*.tbz2) tar xvjf "$1" ;; *.tar) tar xvf "$arg" -C "$dir" ;;
*.tgz) tar xvzf "$1" ;; *.tbz2) tar xvjf "$arg" -C "$dir" ;;
*.xz) xz -dk "$1" ;; *.tgz) tar xvzf "$arg" -C "$dir" ;;
*.zip) mkdir "${1%.*}" && unzip "$1" -d "${1%.zip}" ;; *.zip) unzip "$arg" -d "$dir" ;;
*.Z) uncompress "$1" ;; *.7z) 7z x "$arg" -o"$dir" ;;
*.7z) 7z x "$1" ;; *.bz2) bunzip2 -ck "$arg" > "$dir/${arg%.*}" ;;
*) echo "'$1' cannot be extracted "\ *.gz|*.Z) gunzip -ck "$arg" > "$dir/${arg%.*}" ;;
"via >${FUNCNAME[0]}<" ;; *.xz) unxz -ck "$arg" > "$dir/${arg%.*}" ;;
esac *) echo "'$arg' cannot be extracted "\
else "via >${FUNCNAME[0]}<" ;;
echo "'$1' is not a valid file!" esac
fi else
echo "'$arg' is not a valid file!"
fi
done
} }
# functions for fast traversal through parent directories # functions for fast traversal through parent directories

Loading…
Cancel
Save