]> Sergey Matveev's repositories - schwabrak.git/blobdiff - lib.zsh.rc
More intro links
[schwabrak.git] / lib.zsh.rc
index d4ef1e2286b421c02f6ee2a85d5732d113a821bcff30e8de5f3211aa5f72cd17..f00593f142b68987db23f198857e86763bb12dcad47d2260ff095b4b4b58b5c5 100644 (file)
@@ -1,4 +1,4 @@
-setopt ERR_EXIT EXTENDED_GLOB GLOB_STAR_SHORT
+setopt ERR_EXIT PIPE_FAIL EXTENDED_GLOB GLOB_STAR_SHORT
 
 PERL=${PERL:-perl}
 EDITOR=${EDITOR:-vi}
@@ -10,9 +10,7 @@ die() {
 
 [[ -d issues ]] || die You must run that command in directory with issues/
 
-relpath() {
-    $PERL -mFile::Spec -le "print File::Spec->abs2rel(@ARGV)" $1:a $2:a
-}
+autoload -Uz relative
 
 endash() {
     $PERL -npe 's/(-+)/$1-/g ; s/ /-/g'
@@ -22,8 +20,37 @@ dedash() {
     $PERL -npe 's/([^-])-([^-])/$1 $2/g ; s/-(-+)/$1/g'
 }
 
+split-issue() {
+    local cols=(${(s/-/)1})
+    REPLY=("${cols[1]}-${cols[2]}-${cols[3]:s/T/ /}" ${(j/-/)cols[4,-1]})
+}
+
+# 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
+    {
+        local i
+        for i ({1..40}) print -n -- -
+        print
+    } | colourise magenta:".*"
 }