Skip to content

Instantly share code, notes, and snippets.

@MashukeAlam
Created February 12, 2024 11:46
Show Gist options
  • Save MashukeAlam/a28e4384f26edd89bba69840ec9994a7 to your computer and use it in GitHub Desktop.
Save MashukeAlam/a28e4384f26edd89bba69840ec9994a7 to your computer and use it in GitHub Desktop.
toggle theme
#!/bin/bash
# Function to get the current GNOME theme name
get_current_theme() {
gsettings get org.gnome.desktop.interface gtk-theme | awk -F\' '{print $2}'
}
# Function to toggle between light and dark themes
toggle_theme() {
current_theme=$(get_current_theme)
if [[ "$current_theme" == *"-Light-"* ]]; then
new_theme=${current_theme//-Light-/-Dark-}
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
elif [[ "$current_theme" == *"-Dark-"* ]]; then
new_theme=${current_theme//-Dark-/-Light-}
gsettings set org.gnome.desktop.interface color-scheme 'default'
else
echo "Unsupported theme format: $current_theme"
exit 1
fi
gsettings set org.gnome.desktop.interface gtk-theme "$new_theme"
echo "Theme toggled: $current_theme -> $new_theme"
}
toggle_theme
@MashukeAlam
Copy link
Author

chmod +x <this_file.sh>
sudo mv <this_file.sh?> /usr/local/bin/toggle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment