]> Sergey Matveev's repositories - schwabrak.git/blob - lib.zsh.rc
Get rid of created file
[schwabrak.git] / lib.zsh.rc
1 setopt ERR_EXIT PIPE_FAIL EXTENDED_GLOB GLOB_STAR_SHORT
2
3 PERL=${PERL:-perl}
4 EDITOR=${EDITOR:-vi}
5
6 die() {
7     print $@ >&2
8     exit 1
9 }
10
11 [[ -d issues ]] || die You must run that command in directory with issues/
12
13 autoload -Uz relative
14
15 endash() {
16     $PERL -npe 's/(-+)/$1-/g ; s/ /-/g'
17 }
18
19 dedash() {
20     $PERL -npe 's/([^-])-([^-])/$1 $2/g ; s/-(-+)/$1/g'
21 }
22
23 split-issue() {
24     local cols=(${(s/-/)1})
25     REPLY=("${cols[1]}-${cols[2]}-${cols[3]:s/T/ /}" ${(j/-/)cols[4,-1]})
26 }
27
28 # Usage: colourise ColourSpec:RegExp [ColourSpec:RegExp ...]
29 # It is intended to be a drop-in replacement for supercat utility.
30 # ColourSpec is comma delimited list of ANSI codes for colour setting.
31 # Look for zsh'es Functions/Misc/colors documentation about possible
32 # colour values. For example to set bold red on green background you use
33 # "bold,fg-red,bg-green" as a ColourSpec.
34 # RegExp is POSIX extended regular expression of the text you want to
35 # colourise.
36 colourise() {
37     if [[ -n $NO_COLOR ]] || [[ $# -eq 0 ]] ; then
38         cat
39         return
40     fi
41     (( ${+colour} )) || { autoload -Uz colors ; colors ; }
42     local lc=$'\e[' rc=m colr=""
43     local spec=(${(s/:/)1})
44     shift
45     for c (${(s/,/)${spec[1]}}) colr="${col}${lc}${colour[$c]}${rc}"
46     local re=${(j/:/)spec[2,-1]}
47     sed -E "s/${re}/${colr}&${reset_color}/g" | colourise $@
48 }
49
50 delim() {
51     {
52         local i
53         for i ({1..40}) print -n -- -
54         print
55     } | colourise magenta:".*"
56 }