Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MrFinchMkV/e87bca2c29aa82c511586958be334fae to your computer and use it in GitHub Desktop.
Save MrFinchMkV/e87bca2c29aa82c511586958be334fae 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