summaryrefslogtreecommitdiff
path: root/src/generate_colors.sh
blob: 6e01d580aa9f103455c3b51990c3462bc18fed56 (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
#!/bin/bash
DIST=$1

headerfile=${DIST}/colors.h
shlib=${DIST}/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"