|
2 | 2 | #
|
3 | 3 | # wat if we have more than one template?
|
4 | 4 |
|
| 5 | +temporary=$(mktemp) || exit 1 |
| 6 | +_e='echo -e' |
| 7 | +option= |
| 8 | +string= |
| 9 | +size=0 |
| 10 | + |
5 | 11 | 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/') |
8 | 15 | }
|
9 | 16 |
|
10 |
| -temporary=$(tempfile) || exit 1 |
11 |
| -size=0 |
12 | 17 | 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}" |
18 | 21 | done
|
19 | 22 |
|
20 |
| - |
21 | 23 | 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=('#' ' ####' '#' '#### ') |
38 | 32 | esac
|
39 | 33 |
|
40 |
| - |
41 | 34 | 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 |
43 | 40 | }
|
44 | 41 |
|
45 | 42 | function line {
|
46 |
| - str_repeat "$((size + adjust))" "$1" |
| 43 | + str_repeat "$((size + adjust))" "$1" |
47 | 44 | }
|
48 | 45 |
|
49 | 46 | function line_top {
|
50 |
| - echo "${corner[0]}$(line "${lines[0]}")${corner[1]}" |
| 47 | + $_e "${corner[0]}$(line "${lines[0]}")${corner[1]}" |
51 | 48 | }
|
52 | 49 |
|
53 | 50 | function line_bottom {
|
54 |
| - echo "${corner[2]}$(line "${lines[2]}")${corner[3]}" |
| 51 | + $_e "${corner[2]}$(line "${lines[2]}")${corner[3]}" |
55 | 52 | }
|
56 | 53 |
|
57 |
| -trap line_top \ |
58 |
| -EXIT;line_bottom |
| 54 | +trap line_top \ |
| 55 | +EXIT; line_bottom |
59 | 56 |
|
60 | 57 | while read -r string
|
61 | 58 | 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