Merge pull request #614 from oxnz/master

add multi formats
pull/622/head
Nils Winkler 2015-11-25 08:49:46 +01:00
commit ef7bfd1bdd
1 changed files with 56 additions and 24 deletions

View File

@ -1,27 +1,59 @@
cite about-plugin cite about-plugin
about-plugin 'one command to extract them all...' about-plugin 'one command to extract them all...'
# extract file(s) from compressed status
extract() { extract() {
if [ $# -ne 1 ] local opt
then local OPTIND=1
echo "Error: No file specified." while getopts "hv" opt; do
case "$opt" in
h)
cat <<End-Of-Usage
Usage: ${FUNCNAME[0]} [option] <archives>
options:
-h show this message and exit
-v verbosely list files processed
End-Of-Usage
return
;;
v)
local -r verbose='v'
;;
?)
extract -h >&2
return 1 return 1
fi ;;
if [ -f $1 ] ; then esac
case $1 in done
*.tar.bz2) tar xvjf $1 ;; shift $((OPTIND-1))
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;; [ $# -eq 0 ] && extract -h && return 1
*.rar) unrar x $1 ;; while [ $# -gt 0 ]; do
*.gz) gunzip $1 ;; if [ -f "$1" ]; then
*.tar) tar xvf $1 ;; case "$1" in
*.tbz2) tar xvjf $1 ;; *.tar.bz2|*.tbz|*.tbz2) tar "x${verbose}jf" "$1" ;;
*.tgz) tar xvzf $1 ;; *.tar.gz|*.tgz) tar "x${verbose}zf" "$1" ;;
*.zip) unzip $1 ;; *.tar.xz) xz --decompress "$1"; set -- "$@" "${1:0:-3}" ;;
*.Z) uncompress $1 ;; *.tar.Z) uncompress "$1"; set -- "$@" "${1:0:-2}" ;;
*.7z) 7z x $1 ;; *.bz2) bunzip2 "$1" ;;
*) echo "'$1' cannot be extracted via extract" ;; *.deb) dpkg-deb -x${verbose} "$1" "${1:0:-4}" ;;
*.pax.gz) gunzip "$1"; set -- "$@" "${1:0:-3}" ;;
*.gz) gunzip "$1" ;;
*.pax) pax -r -f "$1" ;;
*.pkg) pkgutil --expand "$1" "${1:0:-4}" ;;
*.rar) unrar x "$1" ;;
*.rpm) rpm2cpio "$1" | cpio -idm${verbose} ;;
*.tar) tar "x${verbose}f" "$1" ;;
*.txz) mv "$1" "${1:0:-4}.tar.xz"; set -- "$@" "${1:0:-4}.tar.xz" ;;
*.xz) xz --decompress "$1" ;;
*.zip|*.war|*.jar) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7za x "$1" ;;
*) echo "'$1' cannot be extracted via extract" >&2;;
esac esac
else else
echo "'$1' is not a valid file" echo "extract: '$1' is not a valid file" >&2
fi fi
shift
done
} }