$PERL -npe 's/([^-])-([^-])/$1 $2/g ; s/-(-+)/$1/g'
}
-supercat() { cat ; }
-if [[ -z $NO_COLOR ]] && command -v spc > /dev/null 2> /dev/null ; then
- supercat() { spc $@ ; }
-fi
+# Usage: colourise ColourSpec:RegExp [ColourSpec:RegExp ...]
+# It is intended to be a drop-in replacement for supercat utility.
+# ColourSpec is comma delimited list of ANSI codes for colour setting.
+# Look for zsh'es Functions/Misc/colors documentation about possible
+# colour values. For example to set bold red on green background you use
+# "bold,fg-red,bg-green" as a ColourSpec.
+# RegExp is POSIX extended regular expression of the text you want to
+# colourise.
+colourise() {
+ if [[ -n $NO_COLOR ]] || [[ $# -eq 0 ]] ; then
+ cat
+ return
+ fi
+ (( ${+colour} )) || { autoload -Uz colors ; colors ; }
+ local lc=$'\e[' rc=m colr=""
+ local spec=(${(s/:/)1})
+ shift
+ for c (${(s/,/)${spec[1]}}) colr="${col}${lc}${colour[$c]}${rc}"
+ local re=${(j/:/)spec[2,-1]}
+ sed -E "s/${re}/${colr}&${reset_color}/g" | colourise $@
+}
delim() {
{
local i
for i ({1..40}) print -n -- -
print
- } | supercat -e mag,".*"
+ } | colourise magenta:".*"
}