Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # convert a Gimp colour palette (.gpl) to a list of CSS variables
- # example:
- # ./gpl-to-css.sh my-palette.gpl > my-palette.css
- # converts
- # ----- my-palette.gpl -----
- # GIMP Palette
- # Name: My Palette
- # Columns: 3
- # 255 0 0 Red
- # 0 255 0 Green
- # 0 0 255 Blue
- # ---------------------------
- # to
- # ----- my-palette.css -----
- # :root {
- # --colour-Red: #ff0000;
- # --colour-Green: #00ff00;
- # --colour-Blue: #0000ff;
- # }
- # ---------------------------
- # only supports 3-column colours
- # you could edit the lines below to enable 4 colours by:
- # - add another match to the regex
- # - shift the indexes of the column items to add a fourth alpha column
- # - add an A colour to the print statement
- regex='^Columns: ([0-9]+)$'
- if [[ $(grep -E "$regex" $1) =~ $regex ]];
- then
- columns=${BASH_REMATCH[1]}
- else
- echo "Error: could not find columns in $1" >&2
- exit 1
- fi
- if [[ $columns -ne 3 ]];
- then
- echo "Error: only 3-column palettes are supported" >&2
- exit 1
- fi
- cat $1 | awk -F ' ' '
- BEGIN {
- printf ":root {\n"
- } /^([0-9]{1,3})\s+([0-9]{1,3})\s+([0-9]{1,3})\s+(.*)$/ {
- colourname = ""
- for (i=4;i<=NF;i++) {
- colourname = colourname "-" $i
- }
- printf " --colour%s: #%02x%02x%02x;\n", colourname, $1, $2, $3
- } END {
- printf "}\n"
- }'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement