From 26cdbf68d048966ce88dc112685bc0dc56329327 Mon Sep 17 00:00:00 2001 From: Thomas Guyot-Sionnest Date: Mon, 6 Apr 2015 14:08:55 -0400 Subject: [PATCH] Merge in fixes; add diff filter --- scripts/colorize.d/df | 12 +++++++----- scripts/colorize.d/diff | 25 +++++++++++++++++++++++++ scripts/colorize.d/misc | 10 ++++++---- scripts/colorize.d/nagios | 10 ++++++---- scripts/colorize.sh | 45 ++++++++++++++++++++++++++------------------- 5 files changed, 70 insertions(+), 32 deletions(-) create mode 100644 scripts/colorize.d/diff diff --git a/scripts/colorize.d/df b/scripts/colorize.d/df index dc573ae..1accc9e 100644 --- a/scripts/colorize.d/df +++ b/scripts/colorize.d/df @@ -1,11 +1,11 @@ #!/bin/bash # Description for --help -DESC="Patterns for interpretting \`df' output (works better with 'df -P')" +DESC="Patterns for interpreting \`df' output (works better with 'df -P')" # Words to highlight - extended regex ("sed -r" compatible) -# Except with the use of '^.+$' for BOLD, having overlapping colors is not -# supported and the result will be unpredictable. +# Except with the use of '^.+$' for BOLD/UNDERLINE, having overlapping colors +# is not supported and the result will be unpredictable. BLACK=() RED=(' 9[0-9]%') GREEN=(' [0-7 ][0-9]%') @@ -14,10 +14,12 @@ BLUE=() MAGENTA=() CYAN=() WHITE=() + +# Bold and Underline are special case, it can be done within and around colors. Be +# aware however that the string may have embedded escape codes at this point. + # Use '^.+$' here to get bright colors everywhere... BOLD=() -# Underline is a special case, it can be done within and around colors. Be -# aware however that the string may have embedded escape codes at this point. UNDERLINE=() diff --git a/scripts/colorize.d/diff b/scripts/colorize.d/diff new file mode 100644 index 0000000..9b30801 --- /dev/null +++ b/scripts/colorize.d/diff @@ -0,0 +1,25 @@ +#!/bin/bash + +# Description for --help +DESC="Patterns for interpreting \`diff -u' output" + +# Words to highlight - extended regex ("sed -r" compatible) +# Except with the use of '^.+$' for BOLD/UNDERLINE, having overlapping colors +# is not supported and the result will be unpredictable. +BLACK=() +RED=('^-.*$') +GREEN=('^\+.*$') +YELLOW=() +BLUE=() +MAGENTA=() +CYAN=() +WHITE=() + +# Bold and Underline are special case, it can be done within and around colors. Be +# aware however that the string may have embedded escape codes at this point. + +# Use '^.+$' here to get bright colors everywhere... +BOLD=('^diff.*$' '^index.*$' '^.{5}---.*$' '^.{5}\+\+\+.*$' '^@.*$') # .{5} matches color escapes + +UNDERLINE=() + diff --git a/scripts/colorize.d/misc b/scripts/colorize.d/misc index 9e0141c..c98f40a 100644 --- a/scripts/colorize.d/misc +++ b/scripts/colorize.d/misc @@ -4,8 +4,8 @@ DESC="Miscellaneous patterns" # Words to highlight - extended regex ("sed -r" compatible) -# Except with the use of '^.+$' for BOLD, having overlapping colors is not -# supported and the result will be unpredictable. +# Except with the use of '^.+$' for BOLD/UNDERLINE, having overlapping colors +# is not supported and the result will be unpredictable. BLACK=() RED=('^.+\.tar\.gz$') GREEN=('^.+\.example\.com') @@ -14,10 +14,12 @@ BLUE=() MAGENTA=() CYAN=() WHITE=() + +# Bold and Underline are special case, it can be done within and around colors. Be +# aware however that the string may have embedded escape codes at this point. + # Use '^.+$' here to get bright colors everywhere... BOLD=() -# Underline is a special case, it can be done within and around colors. Be -# aware however that the string may have embedded escape codes at this point. UNDERLINE=() diff --git a/scripts/colorize.d/nagios b/scripts/colorize.d/nagios index 327f58c..60d9515 100644 --- a/scripts/colorize.d/nagios +++ b/scripts/colorize.d/nagios @@ -4,8 +4,8 @@ DESC="Patterns for Nagios-plugins (OK:/WARNING:/CRITICAL:/UNKNOWN:)" # Words to highlight - extended regex ("sed -r" compatible) -# Except with the use of '^.+$' for BOLD, having overlapping colors is not -# supported and the result will be unpredictable. +# Except with the use of '^.+$' for BOLD/UNDERLINE, having overlapping colors +# is not supported and the result will be unpredictable. BLACK=('UNKNOWN:.+') RED=('CRITICAL:.+') GREEN=('OK:.+') @@ -14,10 +14,12 @@ BLUE=() MAGENTA=() CYAN=() WHITE=() + +# Bold and Underline are special case, it can be done within and around colors. Be +# aware however that the string may have embedded escape codes at this point. + # Use '^.+$' here to get bright colors everywhere... BOLD=('^.+$') -# Underline is a special case, it can be done within and around colors. Be -# aware however that the string may have embedded escape codes at this point. UNDERLINE=() diff --git a/scripts/colorize.sh b/scripts/colorize.sh index 6e4a9b5..3093bc0 100755 --- a/scripts/colorize.sh +++ b/scripts/colorize.sh @@ -40,32 +40,39 @@ fi . "$configdir/$1" # Color codes -fg_BLACK="$(tput setaf 0)" -fg_RED="$(tput setaf 1)" -fg_GREEN="$(tput setaf 2)" -fg_YELLOW="$(tput setaf 3)" -fg_BLUE="$(tput setaf 4)" -fg_MAGENTA="$(tput setaf 5)" -fg_CYAN="$(tput setaf 6)" -fg_WHITE="$(tput setaf 7)" -fg_BOLD="$(tput bold)" -color_reset="$(tput sgr0)" +fg_BLACK="$(echo -e '\e[30m')" +fg_RED="$(echo -e '\e[31m')" +fg_GREEN="$(echo -e '\e[32m')" +fg_YELLOW="$(echo -e '\e[33m')" +fg_BLUE="$(echo -e '\e[34m')" +fg_MAGENTA="$(echo -e '\e[35m')" +fg_CYAN="$(echo -e '\e[36m')" +fg_WHITE="$(echo -e '\e[37m')" +color_reset="$(echo -e '\e[39m')" -# Underline is slightly different -fg_UNDERLINE="$(tput smul)" -underline_reset="$(tput rmul)" +# Bold and Underline are slightly different +fg_BOLD="$(echo -e '\e[1m')" +bold_reset="$(echo -e '\e[0m')" +fg_UNDERLINE="$(echo -e '\e[4m')" +underline_reset="$(echo -e '\e[0m')" + +IFS=$'\n' while read line do sedcmd='' for c in GREEN BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE BOLD UNDERLINE do - if [ $c == UNDERLINE ] - then - reset="$underline_reset" - else - reset="$color_reset" - fi + case $c in + BOLD) + reset="$bold_reset" + ;; + UNDERLINE) + reset="$underline_reset" + ;; + *) + reset="$color_reset" + esac eval "words=(\"\${$c[@]}\")" for w in "${words[@]}" -- 2.11.4.GIT