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