Make it blink with D7 and D8
[rapper.git] / bitbucket_lpc1768 / quiet
1 #!/bin/sh
2 HELP='Usage:
3   quiet fname cmd args ...
4
5 Runs the  passed in command  printing only  "cmd" and "fname"  unless an
6 error  occurs  in which  case  it  prints  the  whole command  line  and
7 colorized program output. Useful  for running compilation commands since
8 it removes the cluter, making it easier to spot errors and warnings.
9
10 '
11 # Copyright (c) 2008-2010 LoEE
12 # This program is released under the new BSD license.
13
14 if [ $# -lt 2 ]; then
15   printf "$HELP"
16   exit
17 fi
18
19 GREEN=""
20 RED=""
21 NORM=""
22 if [ "$TERM@" = "rxvt@" ]; then
23   GREEN="printf \033[32m"
24   RED="printf \033[31m"
25   YELLOW="printf \033[33m" # this is not yellow :)
26   NORM="printf \033[m\017"
27 fi
28 if [ "$OSTYPE@" = "msys@" ]; then
29   OLDATTR=$(eecolor.exe)
30   GREEN="eecolor.exe 0 10"
31   RED="eecolor.exe 0 12"  
32   YELLOW="eecolor 0 14"
33   NORM="eecolor.exe ${OLDATTR}"   
34 fi
35
36 MSG="$(printf "%-16s $1" "$2")"
37 shift;
38
39 printf "${MSG}\r" 1>&2
40
41 rm -f quiet.log
42 "$@" 2>> quiet.log
43 RET=$?
44 # if we check $? we won't notice the warnings
45 if [ $RET -ne 0 -o -s quiet.log ]; then
46   echo "$@" >& 2
47   if [ $RET -ne 0 ]; then
48     $RED >& 2
49   else 
50     $YELLOW >& 2
51   fi
52   cat quiet.log >& 2
53   $NORM &> 2
54
55   exit $RET
56 else
57   $GREEN >& 2
58   printf "${MSG}\n" 1>&2
59   $NORM >& 2
60 fi
61 rm quiet.log
62 exit $RET