commit 8a7053cc581b8c867936e595189ce9191f765a1f
parent c4d97ec06afb0c3d541ede5fbd867f69df2c3629
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Mon, 13 Oct 2025 07:56:02 +0200
feat: add some context and readme
Diffstat:
5 files changed, 62 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,3 @@
+install:
+ mkdir -p ~/.local/share/theme-switchers
+ install -m 700 ./*.sh ~/.local/share/theme-switchers/
diff --git a/README.md b/README.md
@@ -0,0 +1,53 @@
+# theme-switchers
+
+Please send patches or remarks to
+[jayvii+theme-switchers[AT]posteo[DOT]de](jayvii+theme-switchers[AT]posteo[DOT]de)
+
+Tools to switch between dark and light mode of some tools I use.
+
+## Switch themes
+
+You can switch all themes at once with the `switch-themes.sh` script. When
+called without arguments, switches from the current to the other. Can be called
+with either `dark` or `light` to choose a specific:
+
+```bash
+./switch-themes.sh "dark"
+```
+
+The `auto-themes.sh` script switches your themes by daytime. It requires the start and end time of the **light** theme as argument and will set the dark theme in all other cases. Call it for example via cron (e.g. every 5 minutes):
+
+```cron
+*/5 * * * * $HOME/.local/share/theme-switchers/auto-themes.sh "09:00" "23:00"
+```
+
+### GNOME
+Regarding the [GNOME Desktop](https://www.gnome.org/):
+Uses `gsettings` to switch between dark and light mode.
+
+When called without arguments, switches from the current to the other. Can be
+called with either `dark` or `light` to choose a specific:
+
+```bash
+./gnome-switch-theme.sh "dark"
+```
+
+### Helix
+
+Regarding the [Helix editor](https://helix-editor.com/):
+Overrides the `theme` variable within the `config.toml` file.
+
+When called without arguments, switches from the current to the other. Can be
+called with either `dark` or `light` to choose a specific:
+
+```bash
+./helix-switch-theme.sh "dark"
+```
+
+Requires a dark and light theme to be defined in
+`~/.config/helix/autothemes.toml`:
+```toml
+theme_dark = "onedark"
+theme_light = "onelight"
+```
+
diff --git a/auto-themes.sh b/auto-themes.sh
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
# exit on error
-set -e
+set -euo pipefail
# change directory
cd $(dirname -- "${BASH_SOURCE[0]}")
currenttime=$(date +%H:%M)
-if [[ "$currenttime" > "17:00" || "$currenttime" < "09:00" ]]; then
+if [[ "$currenttime" > "$2" || "$currenttime" < "$1" ]]; then
./switch-themes.sh "dark"
else
./switch-themes.sh "light"
diff --git a/gnome-switch-theme.sh b/gnome-switch-theme.sh
@@ -11,6 +11,9 @@ else
target="$1"
fi
+export XDG_RUNTIME_DIR="/run/user/$(id -u)"
+export DBUS_SESSION_BUS_ADDRESS="unix:path=${XDG_RUNTIME_DIR}/bus"
+
# If we want a dark theme, but the current theme is not, switch theme to dark
if [[ "$target" == "'prefer-light'" ]] || [[ "$target" == "dark" ]]; then
gsettings set org.gnome.desktop.interface color-scheme "prefer-dark"
diff --git a/switch-themes.sh b/switch-themes.sh
@@ -10,7 +10,7 @@ cd $(dirname -- "${BASH_SOURCE[0]}")
## GNOME
if [ -f "./gnome-switch-theme.sh" ]; then
- ./gnome-switch-theme.sh "$1"
+ bash -x "./gnome-switch-theme.sh $1"
fi
## Helix