added xrdb fetcher

This commit is contained in:
Simon
2020-12-30 16:53:47 +01:00
parent c05d789689
commit 9b6b350fd8
8 changed files with 301 additions and 1000 deletions
+35
View File
@@ -0,0 +1,35 @@
#!/bin/bash
###########
# Update alacritty config to apply Xresources color scheme
#
# Target file
SKELETON_FILE="$HOME/.config/alacritty/alacritty.skeleton.yml"
TARGET_FILE="$HOME/.config/alacritty/alacritty.yml"
# copy input file to temporary file for black magic fuckery
# (alacritty applies colors when the config file is written, so we want to do it
# all in one write)
cp "$SKELETON_FILE" "$TARGET_FILE.tmp"
# Grab colors from Xresources
xrdb ~/.Xresources
# Named colors
foreground=$(xrdb -query | awk '/*.foreground/ { print substr($2,2) }')
background=$(xrdb -query | awk '/*.background/ { print substr($2,2) }')
sed -i "s/%foreground%/\x270x${foreground}\x27/g" "$TARGET_FILE.tmp"
sed -i "s/%background%/\x270x${background}\x27/g" "$TARGET_FILE.tmp"
# Numbered colors
for i in {0..15}
do
v=$(xrdb -query | awk '/*.color'"$i":'/ { print substr($2,2) }')
eval "sed -i 's/%color${i}%/\x270x${v}\x27/g' $TARGET_FILE.tmp";
done
# Finally, replace target file with our updated one
rm -f "$TARGET_FILE"
mv "$TARGET_FILE.tmp" "$TARGET_FILE"