-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcrayons.sh
More file actions
142 lines (118 loc) · 2.81 KB
/
Copy pathcrayons.sh
File metadata and controls
142 lines (118 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#! /bin/cat
CRAYONS_SOURCE="$BASH_SOURCE"
[[ $NO_COLOUR ]] || . ~/jab/environ.d/colour.sh
.r () {
SOURCED_CRAYONS= source "$CRAYONS_SOURCE"
}
upper () {
echo ${1} | tr '[:lower:]' '[:upper:]'
}
rgb () {
[[ $1 ]] || return 7
local eol_=
if [[ $* =~ (^|[\ ])-[l] ]]; then
eol_="\n"
shift
fi
[[ $1 =~ ^l?(off|red|green|blue|cyan|magenta|black|white)$ ]] || return 8
local colour_=$1
[[ $colour_ ]] || return 9
shift
local light_=
[[ $colour_ =~ ^l ]] && light_=1
[[ $light_ ]] && colour_=${colour_:1}
colour_=$(upper "$colour_")
local sight_=NIGHT_
[[ $light_ ]] && sight_=LIGHT_
local foreground_="$sight_$(upper $colour_)" background_=
if [[ $1 ]]; then
if [[ $1 =~ ^(red|green|blue|cyan|magenta|black|white)$ ]]; then
background_="BACK_$(upper $1)"
shift
fi
fi
local text_="$@"
colour_="${!foreground_}"
[[ $background_ ]] && colour_="${colour_}${!background_}"
if [[ "$text_" ]]; then printf -- "${colour_}${text_}""${NO_COLOUR}"
elif [ ! -t 0 ]; then printf -- "${colour_}$(cat)${NO_COLOUR}"
else printf -- "${NO_COLOUR}"
fi
}
rgb_line () {
rgb "$@" "\n"
}
show_comment () {
grey_line "$@"
}
show_data () {
lblue_line "$@"
}
show_fail () {
red_line "$@" >&2
return 1
}
show_pass () {
lgreen_line "$@"
return 0
}
show_error () {
show_fail "$@"
}
# xxxxxxxxxxx
# xxxxxxxxxxxx
show_command () {
local arg_=
lblack "$ "
lgreen "$1 "
shift
for arg_ in "$@"; do
[[ $arg_ =~ \ ]] && arg_="\"$arg_\""
lblue "$arg_ "
done
echo
}
show_run_command () {
show_command "$@"
echo
"$@" > ~/fd1 2> ~/fd2
if test -s ~/fd1; then
local text_=
grep -q '0m' ~/fd1 && cat ~/fd1 || lblue_line $(cat ~/fd1)
else lblue_line $(cat ~/fd1)
fi
if test -s ~/fd2; then
show_fail $(cat ~/fd2)
fi
}
crayons () {
echo "${BASH_SOURCE}.sh"
}
crayon () {
local function_name_=$1 rgb_colour_=$2
[[ $rgb_colour_ ]] || rgb_colour_=$function_name_
printf "$function_name_ () {\n rgb $rgb_colour_ "'"$@"'" \n}\n\n" >> $(crayons)
}
crayon_line () {
local name_=$1 body_=$2
[[ $body_ ]] || body_=$name_
printf "$name_ () {\n rgb_line $body_ "'"$@"'" \n}\n\n" >> $(crayons)
}
source_crayons () {
local crayons_=$(crayons)
echo > $crayons_
crayon no_colour off
for colour in red green blue cyan magenta yellow black white; do
[[ $colour == "black" ]] || crayon $colour
crayon l$colour
crayon_line ${colour}_line "$colour"
crayon_line l${colour}_line "l$colour"
done
crayon grey lblack
crayon_line grey_line lblack
. $crayons_
}
if [[ ! $SOURCED_CRAYONS ]]; then
source_crayons
SOURCED_CRAYONS=1
fi