#!/bin/bash
#===============================================================================
#
#          FILE: xcat
#
#         USAGE: xcat <gzip/non-gzip file1> [gzip/non-gzip file2] ...
#
#   DESCRIPTION: Combine cat/zcat and automatically switch read mode.
#
#       OPTIONS: <gzip/non-gzip file1> [gzip/non-gzip file2] ...
#
#  REQUIREMENTS: zcat, xz(optional)
#
#         NOTES: 
#
#          BUGS:  ---
#        AUTHOR: rickz (Rick Zhang), xlrickz@gmail.com
#       COMPANY: X-LEGEND Entertainment Corp.
#       CREATED: Mon Aug 15 04:43:19 EDT 2011
#      REVISION: 1.0
#
#          TODO:
#
#===============================================================================

#set -o nounset                              # Treat unset variables as an error
#set -m                                       # Enable job control

[ "$1" == "" ] && exec echo "Usage: $0 <xz/gzip/non-gzip file1> [xz/gzip/non-gzip file2] ..."

IFS='
'

for FILE in $*;do

	ionice -c 3 nice -n 19 $HOME/bin/xz -d -c "$FILE" 2> /dev/null \
        || ionice -c 3 nice -n 19 gzip -d -c "$FILE" 2> /dev/null \
        || ionice -c 3 nice -n 19 cat "$FILE"

done
