forked from githubnando/vim-header-composer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvhc
executable file
·74 lines (60 loc) · 2.09 KB
/
vhc
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
#!/usr/bin/env bash
temporary=$(mktemp) || exit 1
_e='echo -e'
option=
string=
size=0
config() {
search="s/[vhc|λ]+:([a-zA-Z0-9,]*);(.*)\$/"""
option=$($_e "${1}" | sed -r "${search}"'\1/')
string=$($_e "${1}" | sed -r "${search}"'\2/')
strlen=${#string}
}
while read -r string
do config """${string}"
$_e """""${string}" >> "${temporary}"
[[ 0 -lt ${strlen} ]] && size=${strlen}
done
# OPTIONS
case "${option,,}" in
sides) adjust=2; corner=('⎣' '⎦' '⎡' '⎤'); lines=(' ' ' ⎥' ' ' '⎢ ' );;
prettybox|pretty) adjust=2; corner=('└' '┘' '┌' '┐'); lines=('─' ' │' '─' '│ ' );;
quotes) adjust=2; corner=('"' ' ' ' ' '"'); lines=(' ' ' ' ' ' ' ' );;
docblock) adjust=2; corner=(' **/' ' ' '/**' ' '); lines=(' ' ' ' ' ' ' * ' );;
cccomment) adjust=2; corner=(' **/' ' ' '/**' ' '); lines=(' ' ' ' ' ' ' ** ' );;
ccomment) adjust=2; corner=(' */' ' ' '/*' ' '); lines=(' ' ' ' ' ' ' * ' );;
lcomment) adjust=2; corner=('//' ' ' '//' ' '); lines=(' ' ' ' ' ' '// ' );;
box) adjust=2; corner=('+' '+' '+' '+'); lines=('-' ' |' '-' '| ' );;
star|stars|asterisk) adjust=2; corner=('*' '*' '*' '*'); lines=('*' ' *' '*' '* ' );;
ernjs|ernando|*) adjust=8; corner=('#' '#' '#' '#'); lines=('#' ' ####' '#' '#### ')
esac
#/OPTIONS
str_repeat() {
n="${1}"
while [[ ${n} -gt 0 ]]
do $_e -n "${2}"
n=$(( n - 1 ))
done
}
remove_trail() {
sed -e 's/[ ]*$//g'
}
line() {
[ $# -eq 1 ] \
&& str_repeat "$((size + adjust))" "${1}" \
&& exit
$_e "${corner[${1}]}$(line "${lines[${1}]}")${corner[${2}]}"
}
line_top() {
line 0 1 | remove_trail
}
line_bottom() {
line 2 3 | remove_trail
}
trap line_top \
EXIT; line_bottom
while read -r string
do tab=$(printf '%*s' $((size - ${#string})) "")
$_e "${lines[3]}${string}${tab}${lines[1]}" | remove_trail
done < "${temporary}"
rm "${temporary}"