Alacritty: update colorscheme switcher

This commit is contained in:
Akemi Izuko 2023-12-30 13:25:48 -07:00
parent acc4e1a2fd
commit 69fa8c4ddc
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC

View file

@ -25,13 +25,14 @@ $(__print_current_colors)
HELP HELP
} }
# Detect current alacritty color scheme # Detect current alacritty color scheme
declare COLOR_SCHEME declare COLOR_SCHEME
declare -r ALACRITTY_COLO=~/.config/alacritty/colors.yml declare -r ALACRITTY_CONF=~/.config/alacritty/alacritty.toml
declare -r VIMIV_CONF=~/.config/vimiv/vimiv.conf declare -r VIMIV_CONF=~/.config/vimiv/vimiv.conf
if [[ -r "$ALACRITTY_COLO" ]]; then if [[ -r "$ALACRITTY_CONF" ]]; then
COLOR_SCHEME="$(awk -F '*' '/^colors:/ { print $2 }' "$ALACRITTY_COLO")" COLOR_SCHEME="$(awk -F/ '/^import =/ {print substr($NF, 1, length($NF)-7)}' "$ALACRITTY_CONF")"
else else
COLOR_SCHEME='base16-gruvbox-dark-pale' COLOR_SCHEME='base16-gruvbox-dark-pale'
fi fi
@ -63,8 +64,24 @@ __change_colors_to() {
# Updates the color scheme for alacritty. Best with alacritty's live reload # Updates the color scheme for alacritty. Best with alacritty's live reload
__change_alacritty_colors() { __change_alacritty_colors() {
local tmp="$(mktemp)" local tmp="$(mktemp)"
awk -v c="$COLOR_SCHEME" '/^colors: /{ $2="*"c } 1' "$ALACRITTY_COLO" > "$tmp" awk \
mv -f "$tmp" "$ALACRITTY_COLO" -v c="$COLOR_SCHEME" \
'/^import =/ {
split($0, a, "/");
$0="";
for (i in a) {
if (i != length(a)) {
$0 = $0 sprintf("%s/", a[i]);
}
}
$0 = $0 c ".toml\"]"
} 1' \
"$ALACRITTY_CONF" \
> "$tmp"
mv -f "$tmp" "$ALACRITTY_CONF"
} }
__change_vimiv_colors() { __change_vimiv_colors() {