-
Notifications
You must be signed in to change notification settings - Fork 922
/
Copy pathgen-chroma-styles.sh
executable file
·71 lines (58 loc) · 1.39 KB
/
gen-chroma-styles.sh
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
#!/bin/bash
set -eo pipefail
HUGO="npx hugo"
CHROMA_STYLE=tango
DEST_DIR=assets/scss/td/chroma
DEST_FILE=_light.scss
DEST_PATH=/dev/null # Set in process_CLI_args
function _usage() {
cat <<EOS
Usage: `basename $0` [options]
Generate CSS for the named Chroma style using Hugo.
-h Output this usage info.
-o FILE Output file name relative to $DEST_DIR.
Default: $DEST_FILE.
-s STYLE Chroma style name from list at
https://xyproto.github.io/splash/docs
Default: $CHROMA_STYLE.
EOS
}
function usage() {
local status=${1:-0}
_usage 1>&2
exit $status
}
function process_CLI_args() {
while getopts ":ho:s:" opt; do
case $opt in
h)
usage
;;
o)
DEST_FILE="$OPTARG"
;;
s)
CHROMA_STYLE="$OPTARG"
;;
\?)
echo "ERROR: unrecognized flag: -$OPTARG"
usage 1;
;;
esac
done
shift $((OPTIND-1))
if [ "$#" -gt 0 ]; then
echo "ERROR: extra argument(s): $*" >&2
usage 1;
fi
DEST_PATH="$DEST_DIR/$DEST_FILE"
}
function main() {
process_CLI_args "$@"
# For more options, see https://gohugo.io/commands/hugo_gen_chromastyles/
local cmd="$HUGO gen chromastyles --style=$CHROMA_STYLE >> $DEST_PATH"
echo "Generating $DEST_FILE using: $cmd"
echo "/* Chroma style: $CHROMA_STYLE */" > $DEST_PATH
eval "$cmd"
}
main "$@"