Skip to content

Instantly share code, notes, and snippets.

@zacharied
Created March 21, 2018 06:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zacharied/e33300ce340caa70499d516ed8ac8de6 to your computer and use it in GitHub Desktop.
Save zacharied/e33300ce340caa70499d516ed8ac8de6 to your computer and use it in GitHub Desktop.
Create an alacritty color config from the current X resources
#!/usr/bin/env bash
# Generates an alacritty color config from currently loaded X resources.
xrdb_grep() {
xrdb -query | grep -E '^\*'"$1"':'
}
color_from_line() {
read -r line && readonly line
echo "${line/\#/0x}" | tr -d '[:space:]' | cut -d ':' -f 2
}
readonly color_idx=(black red green yellow blue magenta cyan white)
# Begin to print alacritty config.
printf 'colors:\n'
printf ' primary:\n'
printf ' background:\t%s\n' "$(xrdb_grep 'background' | color_from_line)"
printf ' foreground:\t%s\n' "$(xrdb_grep 'foreground' | color_from_line)"
printf ' normal:\n'
declare -i i=0
while read -r line; do
if [[ $i == 8 ]]; then
printf ' bright:\n'
fi
printf ' %s:\t%s\n' \
"${color_idx[((i % 8))]}" \
"$(echo "$line" | color_from_line)"
i+=1
done < <(xrdb_grep 'color[[:digit:]]+' | sort -V)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment