fix(bin): alacritty automatic theme changing

This commit is contained in:
2024-07-30 00:22:07 +03:00
parent dc76fa8914
commit e329868568
2 changed files with 10 additions and 5 deletions

View File

@@ -71,7 +71,7 @@ darknotify_alacritty()
x-have dark-notify && { x-have dark-notify && {
# subprocess is used to prevent the command from showing it was backgrounded # subprocess is used to prevent the command from showing it was backgrounded
( (
silent flock /tmp/dark-notify-alacritty.lock dark-notify \ flock /tmp/dark-notify-alacritty.lock dark-notify \
-c "$HOME/.dotfiles/local/bin/x-change-alacritty-theme" & -c "$HOME/.dotfiles/local/bin/x-change-alacritty-theme" &
) &> /dev/null ) &> /dev/null
} }

View File

@@ -14,7 +14,7 @@ A_DIR="$HOME/.config/alacritty"
usage() usage()
{ {
echo "Usage: $0 <theme>" echo "Usage: $0 <theme>"
echo "Available themes: dark, night, day" echo "Available themes: (dark|night) to turn dark mode on, (day|light) to turn off"
exit 1 exit 1
} }
@@ -23,6 +23,7 @@ usage()
msg() msg()
{ {
[[ "$VERBOSE" -eq 1 ]] && echo "$1" [[ "$VERBOSE" -eq 1 ]] && echo "$1"
return 0
} }
# Function to set the alacritty theme # Function to set the alacritty theme
@@ -30,8 +31,10 @@ msg()
set_alacritty_theme() set_alacritty_theme()
{ {
local theme=$1 local theme=$1
msg "Setting alacritty theme to $theme" local theme_file="$A_DIR/theme-$theme.toml"
cp -f "$A_DIR/theme-$theme.toml" "$A_DIR/theme-active.toml" msg "Setting alacritty theme to $theme ($theme_file)"
cp -f "$theme_file" "$A_DIR/theme-active.toml"
return 0
} }
# Function to notify alacritty about the changes # Function to notify alacritty about the changes
@@ -39,6 +42,7 @@ notify_alacritty()
{ {
msg "Notifying alacritty about the changes" msg "Notifying alacritty about the changes"
touch "$A_DIR/alacritty.toml" touch "$A_DIR/alacritty.toml"
return 0
} }
# Main function # Main function
@@ -51,7 +55,7 @@ main()
local alacritty_theme=$1 local alacritty_theme=$1
case "$alacritty_theme" in case "$alacritty_theme" in
day) day | light)
set_alacritty_theme "day" set_alacritty_theme "day"
;; ;;
*) *)
@@ -61,6 +65,7 @@ main()
notify_alacritty notify_alacritty
msg "Theme set successfully!" msg "Theme set successfully!"
exit 0
} }
main "$@" main "$@"