summaryrefslogtreecommitdiff
path: root/src/generate_colors.sh
blob: 3acbb509021df57ed3e783348ade2350c7d7ea13 (plain)
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
#!/bin/bash

PREFIX=$1

headerfile=${PREFIX}"/include/colors.h"
shlib=${PREFIX}"/lib/colors.sh"

cat > $shlib << "EOF"
#
# colors.h
#
# list of ansi color codes
# provided by xiutils
#

EOF

cat > $headerfile << "EOF"
/*
 * colors.h
 *
 * list of ansi color codes
 * provided by xiutils
 *
 */

EOF

append_header() {
    echo "#define $1 $2" >> $headerfile
}

append_sh() {
    printf 'export %s=$(printf %s)\n' $1 $2 >> $shlib
}

while IFS= read -r line; do
    echo "$line" | grep -q "." || continue
    name=$(echo $line | awk '{ print $1 }')
    code=$(echo $line | awk '{ print $2 }')

    append_header $name $code
    append_sh $name $code
    
done < "$2"