summaryrefslogtreecommitdiffstats
path: root/roles/hyprtheme/files/scripts/theme.sh
blob: 14be33c71934f0e11e7f311236bb54048227e588 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash

show_themes() {
  local available_themes=$(ls -1p $HOME/.config/hyprtheme/themes/ | grep "/" | cut -f1 -d'/')
  local selected_theme=$(printf "$available_themes" | tofi \
    --prompt-text "Select: " \
    --placeholder-text "Theme"
  )

  if [[ -n "$selected_theme" ]]; then
    select_theme "$selected_theme"
  fi
}

select_theme() {
  local theme_name="$1"
  local themes_path="$HOME/.config/hyprtheme/themes"
  local current_theme_path="$HOME/.config/hyprtheme/current"

  if [[ ! -d "$themes_path/$theme_name" ]]; then
    notify-send -e \
        -h string:x-canonical-private-synchronous:themes \
        -u critical \
        "Theme" \
        "Theme '$theme_name' doesn't exist"
    exit 1
  fi

  # Get close to as atomic as possible.
  ln -sfn "$themes_path/$theme_name" "$current_theme_path.new"
  rm -rf "$current_theme_path"
  mv "$current_theme_path.new" "$current_theme_path"

  # Prompt wallpaper selection
  "$HOME/.config/hyprtheme/scripts/wallpaper.sh" #$(find "$current_theme_path/wallpapers" -type f | head -1)

  pkill -x waybar || true
  setsid uwsm-app -- waybar >/dev/null 2>&1 &

  hyprctl reload >/dev/null 2>&1

  pkill -SIGUSR2 btop || true

  makoctl reload

  if [[ -f ~/.config/alacritty/alacritty.toml ]]; then
    touch ~/.config/alacritty/alacritty.toml
  fi
  killall -SIGUSR1 kitty >/dev/null 2>&1 || true
  killall -SIGUSR2 ghostty >/dev/null 2>&1 || true

  if [[ -f ~/.config/hyprtheme/current/light.mode ]]; then
    gsettings set org.gnome.desktop.interface color-scheme "prefer-light"
    gsettings set org.gnome.desktop.interface gtk-theme "Adwaita"
    gsettings set org.gnome.desktop.interface font-name "Noto Sans"
  else
    gsettings set org.gnome.desktop.interface color-scheme "prefer-dark"
    gsettings set org.gnome.desktop.interface gtk-theme "Adwaita-dark"
    gsettings set org.gnome.desktop.interface font-name "Noto Sans"
  fi
}

if [[ -z "$1" ]]; then
  show_themes
else
  select_theme "$1"
fi