Coloured logs

From AssaultCube

Jump to: navigation, search
  1. #!/bin/sh
  2.  #
  3.  # CatCuBeLog
  4.  # by MeatROme - historically interesting, done by engine-code nowadays ;)
  5.  
  6.  C_="\033[m"
  7.  
  8.  # 0 : green, 1 : blue, 2 : yellow, 3 : red, 4 : gray, >=5 : white
  9.  # 0 : 32     1 : 34    2 : 33      3 : 31   4 : 37      5 : 1
  10.  
  11.  C0=32
  12.  C1=36
  13.  C2=33
  14.  C3=31
  15.  
  16.  # post gui-release| sed s/^/"$C5"/g
  17.  C4="1\;30"
  18.  C5="1\;37"
  19.  
  20.  S0=""
  21.  if [ "$1" != "-" ]
  22.  then
  23.         S0="$(cat "${1}" | sed 's/^/\\033[40m\\033[1;37m\ /g')"
  24.  else
  25.         S0="$(cat /dev/stdin | sed 's/^/\\033[40m\\033[1;37m\ /g')"
  26.  fi
  27.  S1=$S0
  28.  CX=0
  29.  for cc in $C0 $C1 $C2 $C3 $C4 $C5; do
  30.         S1=$(echo "$S1" | sed s/^${CX}/\\\\033[${cc}m/g)
  31.         CX=$(echo 1+$CX|bc)
  32.  done
  33.  # eliminate other colour-chars quietly
  34.  S2=$(echo "$S1" | sed 's/^./\\033[1;37m/g')
  35.  S1="$S2"
  36.  # eliminate dangling colour setting
  37.  S3=$(echo "$S1" | sed 's/$/\\033[m/g')
  38.  S1="$S3"
  39.  if [ -n "$2" ]
  40.  then
  41.         case "$2" in
  42.                 "-s")
  43.                         echo "$(echo "$S1$C_" | awk -f /usr/local/bin/.awk/history.awk | sort -n | sed 's/\ /\\033[1;37m\t\t/2' | sed 's/^/\ \\033[1;34m/g')"
  44.                 ;;
  45.                 "-u")
  46.                         echo "$S1$C_" | sort | uniq -c | egrep -v "^\ +1\ "
  47.                 ;;
  48.                 *)
  49.                         echo "$S1$C_"
  50.                 ;;
  51.         esac   
  52.  else
  53.         echo "$S1$C_"
  54.  fi

This makes use of the following awk-file .. which I don't remember where I found it originally. If you don't change the location in the source above, place this into /usr/local/bin/.awk/history.awk

# histsort.awk --- compact a shell history file
 # Thanks to Byron Rakitzis for the general idea
 {
     if (data[$0]++ == 0)
         lines[++count] = $0
 }
 
 END {
     for (i = 1; i <= count; i++)
     print data[lines[i]], lines[i]
 
     #print lines[i]
 
 }
Personal tools