]> Sergey Matveev's repositories - schwabrak.git/commitdiff
supercatlessness
authorSergey Matveev <stargrave@stargrave.org>
Thu, 21 Mar 2024 21:37:12 +0000 (00:37 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 21 Mar 2024 21:37:12 +0000 (00:37 +0300)
lib.zsh.rc
list
show

index e4b582ba06148b347ba523054814dfef7be95e9386502ddffd3670f6198dc170..09e19535e0ac16400b1f0df655461323afee5d43842162faf0f2b60f3eab3260 100644 (file)
@@ -20,15 +20,32 @@ dedash() {
     $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:".*"
 }
diff --git a/list b/list
index 13a1be1d441e081f68883edb4ff2da014f1c5592271e42217722ec2e8aee42d6..e6e13a3c8baf4fbd1dc17a726f8feedfe0c9f2ecb6ccd1311e2d185e5008b616 100755 (executable)
--- a/list
+++ b/list
@@ -43,4 +43,4 @@ for issue (issues/**/created) {
     print -n `cat issues/$issue/created`\\t$issue\\t
     print $tagsTheir
 } | sort -r |
-supercat -e grn,"^.{19}" -e cya,"      [^      ]*$" -e red,"   .*\/"
+colourise green:"^.{19}" cyan:"        [^      ]*$" red:"      .*\/"
diff --git a/show b/show
index e405bdec3cfcd9475fa6d89d5bc20b47417454bf4f9cbd57f10d195c1fa85715..45b6a93372da51c42982ad6dec3adeca0035058ea0ef37c233326284544e9074 100755 (executable)
--- a/show
+++ b/show
@@ -4,9 +4,9 @@ root=$0:h:a
 . $root/lib.zsh.rc
 
 issue=${1#issues/}
-print $issue:h | supercat -e red,".*" | read proj
+print $issue:h | colourise red:".*" | read proj
 print `cat issues/$issue/created` \| $proj/`print $issue:t | dedash`
-$root/tag-list $issue | supercat -e cya,".*"
+$root/tag-list $issue | colourise cyan:".*"
 deps=(issues/$issue/deps/*(N))
 [[ ${#deps} -eq 0 ]] || {
     delim