Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa66292

Browse files
committed
adding more templates
1 parent 4e39d06 commit fa66292

File tree

1 file changed

+33
-37
lines changed

1 file changed

+33
-37
lines changed

vhc

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,60 @@
22
#
33
# wat if we have more than one template?
44

5+
temporary=$(mktemp) || exit 1
6+
_e='echo -e'
7+
option=
8+
string=
9+
size=0
10+
511
function config {
6-
option=$(echo "$1"|sed -r 's/vhc:([a-z,]*);(.*)$/\1/')
7-
string=$(echo "$1"|sed -r 's/vhc:([a-z,]*);(.*)$/\2/')
12+
o='s/vhc:([a-z,]*);(.*)$/'
13+
option=$($_e "$1"|sed -r "${o}"'\1/')
14+
string=$($_e "$1"|sed -r "${o}"'\2/')
815
}
916

10-
temporary=$(tempfile) || exit 1
11-
size=0
1217
while read -r string
13-
do
14-
[[ "${string:0:4}" == "vhc:" ]] && config "$string"
15-
16-
echo "${string}" >> "$temporary"
17-
[[ ${#string} -gt ${size} ]] && size=${#string}
18+
do [[ "${string:0:4}" == "vhc:" ]] && config "${string}"
19+
[[ ${#string} -gt ${size} ]] && size=${#string}
20+
$_e "${string}" >> "${temporary}"
1821
done
1922

20-
2123
case "${option,,}" in
22-
box)
23-
adjust=2
24-
corner=('+' '+' '+' '+')
25-
lines=('-' ' |' '-' '| ')
26-
;;
27-
28-
star|stars|asterisk)
29-
adjust=2
30-
corner=('*' '*' '*' '*')
31-
lines=('*' ' *' '*' '* ')
32-
;;
33-
34-
ernjs|ernando|*)
35-
adjust=8
36-
corner=('#' '#' '#' '#')
37-
lines=('#' ' ####' '#' '#### ')
24+
sides) adjust=2; corner=('' '' '' ''); lines=(' ' '' ' ' '' );;
25+
prettybox) adjust=2; corner=('' '' '' ''); lines=('' '' '' '' );;
26+
quotes) adjust=2; corner=('"' ' ' ' ' '"'); lines=(' ' ' ' ' ' ' ' );;
27+
ccomment) adjust=2; corner=(' */' ' ' '/*' ' '); lines=(' ' ' ' ' ' ' * ');;
28+
lcomment) adjust=2; corner=('//' ' ' '//' ' '); lines=(' ' ' ' ' ' '// ');;
29+
box) adjust=2; corner=('+' '+' '+' '+'); lines=('-' ' |' '-' '| ' );;
30+
star|stars|asterisk) adjust=2; corner=('*' '*' '*' '*'); lines=('*' ' *' '*' '* ' );;
31+
ernjs|ernando|*) adjust=8; corner=('#' '#' '#' '#'); lines=('#' ' ####' '#' '#### ')
3832
esac
3933

40-
4134
function str_repeat {
42-
printf '%*s' "$1" | tr ' ' "$2"; echo
35+
n=$1
36+
while [[ $n -gt 0 ]]
37+
do $_e -n "$2"
38+
n=$(( n - 1 ))
39+
done
4340
}
4441

4542
function line {
46-
str_repeat "$((size + adjust))" "$1"
43+
str_repeat "$((size + adjust))" "$1"
4744
}
4845

4946
function line_top {
50-
echo "${corner[0]}$(line "${lines[0]}")${corner[1]}"
47+
$_e "${corner[0]}$(line "${lines[0]}")${corner[1]}"
5148
}
5249

5350
function line_bottom {
54-
echo "${corner[2]}$(line "${lines[2]}")${corner[3]}"
51+
$_e "${corner[2]}$(line "${lines[2]}")${corner[3]}"
5552
}
5653

57-
trap line_top \
58-
EXIT;line_bottom
54+
trap line_top \
55+
EXIT; line_bottom
5956

6057
while read -r string
6158
do spacing=$(printf '%*s' $((size - ${#string})))
62-
echo "${lines[3]}${string}${spacing}${lines[1]}"
63-
done < "$temporary"
64-
65-
rm "$temporary"
59+
$_e "${lines[3]}${string}${spacing}${lines[1]}"
60+
done < "${temporary}"
61+
rm "${temporary}"

0 commit comments

Comments
 (0)