Created
March 21, 2018 06:19
-
-
Save zacharied/e33300ce340caa70499d516ed8ac8de6 to your computer and use it in GitHub Desktop.
Create an alacritty color config from the current X resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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