toggle-theme.sh 1023 B

12345678910111213141516171819202122232425262728293031
  1. #!/bin/bash
  2. # Script to toggle between light / dark mode
  3. # Set this to where Waybar reads its config files
  4. WAYBAR_DIR="$HOME/.config/waybar"
  5. SWAYNC_DIR="$HOME/.config/swaync"
  6. CURRENT_SCHEME=$(gsettings get org.gnome.desktop.interface color-scheme)
  7. if [ "$CURRENT_SCHEME" == "'prefer-dark'" ]; then
  8. gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'
  9. # Copy the light theme to theme.css
  10. cp "$WAYBAR_DIR/light.css" "$WAYBAR_DIR/theme.css"
  11. cp "$SWAYNC_DIR/light.css" "$SWAYNC_DIR/theme.css"
  12. notify-send "Light Mode" -a "System"
  13. else
  14. gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
  15. # Copy the dark theme to theme.css
  16. cp "$WAYBAR_DIR/dark.css" "$WAYBAR_DIR/theme.css"
  17. cp "$SWAYNC_DIR/dark.css" "$SWAYNC_DIR/theme.css"
  18. notify-send "Dark Mode" -a "System"
  19. fi
  20. # Sends signals to these processes to speed up the theme switch
  21. killall -SIGUSR2 waybar
  22. killall -SIGUSR1 nvim
  23. pkill -SIGHUP wezterm
  24. # Reload SwayNC CSS styling cleanly
  25. swaync-client -rs