Skip to content

Instantly share code, notes, and snippets.

@yhkaplan
Last active August 5, 2021 05:34
Show Gist options
  • Save yhkaplan/c18393663bb7b7714017ab58cfc7fe4d to your computer and use it in GitHub Desktop.
Save yhkaplan/c18393663bb7b7714017ab58cfc7fe4d to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
extract_name() {
echo "$1" | sed -rn 's/.*\/(.*)\.colorset.*/\1/p'
}
extract_hex() {
FILE_CONTENTS=$(cat "$1")
COMPONENTS=$(echo "$FILE_CONTENTS" | jq '.colors[0].color.components')
R=$(echo "$COMPONENTS" | jq '.red' --raw-output | cut -c 3-)
G=$(echo "$COMPONENTS" | jq '.green' --raw-output | cut -c 3-)
B=$(echo "$COMPONENTS" | jq '.blue' --raw-output | cut -c 3-)
echo "$R$G$B"
}
echo "Color | Name | Hex"
echo "-|-|-"
COLORSETS=$(find . -name '*Contents.json' | grep "colorset")
IFS=$'\n'
for file in $COLORSETS
do
NAME=$(extract_name "$file")
HEX=$(extract_hex "$file")
COLOR="![$NAME](https://via.placeholder.com/15/$HEX/000000?text=+)"
echo "$COLOR | $NAME | #$HEX"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment