#!/usr/bin/env bash # Function to detect if the OS theme is dark is_dark_theme() { # Method 1: gsettings (GNOME/GTK color-scheme) if command -v gsettings >/dev/null 2>&1; then local scheme scheme=$(gsettings get org.gnome.desktop.interface color-scheme 2>/dev/null | tr -d "'") if [ "$scheme" = "prefer-dark" ]; then return 0 elif [ "$scheme" = "prefer-light" ]; then return 1 fi fi # Method 2: XDG Desktop Portal dbus query (desktop-agnostic portal) if command -v dbus-send >/dev/null 2>&1; then local dbus_val dbus_val=$(dbus-send --print-reply --dest=org.freedesktop.portal.Desktop \ /org/freedesktop/portal/desktop \ org.freedesktop.portal.Settings.Read \ string:'org.freedesktop.appearance' string:'color-scheme' 2>/dev/null) if echo "$dbus_val" | grep -q "uint32 1"; then return 0 # Dark elif echo "$dbus_val" | grep -q "uint32 2"; then return 1 # Light fi fi # Method 3: Fallback check on GTK theme name for "dark" if command -v gsettings >/dev/null 2>&1; then local gtk_theme gtk_theme=$(gsettings get org.gnome.desktop.interface gtk-theme 2>/dev/null | tr -d "'" | tr '[:upper:]' '[:lower:]') if [[ "$gtk_theme" =~ "dark" || "$gtk_theme" =~ "black" || "$gtk_theme" =~ "night" ]]; then return 0 fi fi # Default fallback to dark theme return 0 } # Determine the correct theme based on the OS theme if is_dark_theme; then THEME="rose_pine" else THEME="rose_pine_dawn" fi # Launch rofi with the selected theme, forwarding any passed arguments exec rofi -theme "$THEME" "$@"