#!/bin/bash
#                      /usr/local/bin/dearchive
# http://crystalfaeries.net/posix/bin/dearchive
# celeste:crystalfaery DEARCHIVE 2017-08-12 17:50:04+00:00
# Originally inspired by:
# http://www.itworld.com/article/2895888/extracting-content-without-the-hassle.html

let exitval=0	# default success
verbose=""	# default succinct
gverbose=""	# default succinct
list=""		# default succinct
while [ $# -ne 0 ]
do	# iterate arguments
	if [ -f "$1" ]
	then	# argument is a valid filename
		case "$1" in
		*.tar.bz2)	tar		 "$verbose"xjf	"$1";;
		*.tbz)		tar		 "$verbose"xjf	"$1";;
		*.tbz2)		tar		 "$verbose"xjf	"$1";;
		*.bz2)		bunzip2		"$gverbose"	"$1";;
		*.tar.gz)	tar		 "$verbose"xzf	"$1";;
		*.tgz)		tar		 "$verbose"xzf	"$1";;
		*.gz)		gunzip		"$gverbose"	"$1";;
		*.tar)		tar		 "$verbose"xf	"$1";;
		*.rar)		rar		 "$verbose"x	"$1";;
		*.zip)		unzip -LL			"$1";;
		*.ZIP)		unzip -LL			"$1";;
		*.Z)		uncompress	"$gverbose"	"$1";;
		*.7z)		7z		x"$list"	"$1";;
		*.xz)		unxz		"$gverbose"	"$1";;
		*.txz)		unxz		"$gverbose"	"$1";;
		*)		echo	"$0 does not know how to extract from $1"	1>&2; let exitval=-1;;
		esac
	else	# argument is not a valid filename
		case "$1" in
		--help)		cat<<EOF
$0 extracts from archives whose filepaths are given as arguments.
Optionally specify '--verbose' for extraction details of all following files.
Informational invocations utilize either '--help' or '--version' options.
EOF
				exit $exitval;;
		--version)	head -n 4 $0 | tail -n 1 | sed 's/^# celeste:crystalfaery //'; exit $exitval;;
		--verbose)	verbose="v";gverbose="-v";list="l";;
		*)		echo	"$0 found no file named $1 operating in `pwd`." 1>&2; let exitval=-2;;
		esac
	fi
	shift	# done with current argument
done		# iterating	    arguments
exit	$exitval


syntax highlighted by Code2HTML, v. 0.9.1