2012-02-01 05:37:51 +01:00
|
|
|
#
|
2013-05-25 20:39:51 +02:00
|
|
|
# Lists the contents of archives.
|
2012-02-01 05:37:51 +01:00
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
|
|
|
#
|
|
|
|
|
2011-10-12 05:13:58 +02:00
|
|
|
local verbose
|
|
|
|
|
|
|
|
if (( $# == 0 )); then
|
2012-01-19 08:28:01 +01:00
|
|
|
cat >&2 <<EOF
|
|
|
|
usage: $0 [-option] [file ...]
|
|
|
|
|
|
|
|
options:
|
|
|
|
-v, --verbose verbose archive listing
|
|
|
|
|
|
|
|
Report bugs to <sorin.ionescu@gmail.com>.
|
|
|
|
EOF
|
2011-10-12 05:13:58 +02:00
|
|
|
fi
|
|
|
|
|
2012-01-27 20:48:33 +01:00
|
|
|
if [[ "$1" == "-v" || "$1" == "--verbose" ]]; then
|
2011-10-12 05:13:58 +02:00
|
|
|
verbose=0
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
while (( $# > 0 )); do
|
2012-04-16 20:21:29 +02:00
|
|
|
if [[ ! -s "$1" ]]; then
|
2012-01-19 08:28:01 +01:00
|
|
|
print "$0: file not valid: $1" >&2
|
2011-10-12 05:13:58 +02:00
|
|
|
shift
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
(*.tar.gz|*.tgz) tar t${verbose:+v}vzf "$1" ;;
|
|
|
|
(*.tar.bz2|*.tbz|*.tbz2) tar t${verbose:+v}jf "$1" ;;
|
|
|
|
(*.tar.xz|*.txz) tar --xz --help &> /dev/null \
|
|
|
|
&& tar --xz -t${verbose:+v}f "$1" \
|
|
|
|
|| xzcat "$1" | tar t${verbose:+v}f - ;;
|
|
|
|
(*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \
|
|
|
|
&& tar --lzma -t${verbose:+v}f "$1" \
|
|
|
|
|| lzcat "$1" | tar x${verbose:+v}f - ;;
|
|
|
|
(*.tar) tar t${verbose:+v}f "$1" ;;
|
|
|
|
(*.zip) unzip -l${verbose:+v} "$1" ;;
|
2013-05-14 23:06:24 +02:00
|
|
|
(*.rar) unrar &> /dev/null \
|
|
|
|
&& unrar ${${verbose:+v}:-l} "$1" \
|
|
|
|
|| rar ${${verbose:+v}:-l} "$1" ;;
|
2011-10-12 05:13:58 +02:00
|
|
|
(*.7z) 7za l "$1" ;;
|
|
|
|
(*)
|
2012-01-19 08:28:01 +01:00
|
|
|
print "$0: cannot list: $1" >&2
|
2011-10-12 05:13:58 +02:00
|
|
|
success=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|