From d81aed5899030da58d6ba7ad71e28838b74676af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Mon, 14 May 2018 18:57:50 +0800 Subject: [PATCH] Auto dectect gzip for catlog --- bash/bashrc/sources/60_diagnostics | 31 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/bash/bashrc/sources/60_diagnostics b/bash/bashrc/sources/60_diagnostics index 02b0127..ce40af3 100755 --- a/bash/bashrc/sources/60_diagnostics +++ b/bash/bashrc/sources/60_diagnostics @@ -1,24 +1,21 @@ #!/bin/bash function catlog () { - if [[ -z "$1" ]]; then - __func_head "[z] FILE" - echo " Will exclude:" - cat ~/.settings/checklog_exclude | awk '{ print " "$1 }' - echo - else - GZIP=false - if [ "$1" == "z" ]; then - GZIP=true - shift - fi + if [[ -z "$1" ]]; then + __func_head "FILE" + echo " Will exclude:" + cat ~/.settings/checklog_exclude | awk '{ print " "$1 }' + echo + else + GZIP= + file "$1" | grep gzip > /dev/null && GZIP=true - EXCLUDE=$(awk '{ printf("(%s)|", $1) }' ~/.settings/checklog_exclude | sed 's/|$//') + EXCLUDE=$(awk '{ printf("(%s)|", $1) }' ~/.settings/checklog_exclude | sed 's/|$//') - if $GZIP; then - gunzip -c $1 | egrep -v $EXCLUDE - else + if [ $GZIP ]; then + gunzip -c $1 | egrep -v $EXCLUDE + else egrep -v $EXCLUDE $1 - fi - fi + fi + fi }