Last active
January 27, 2020 12:48
-
-
Save sillyslux/84b771429f81b58a6d58e8b08a67ea7b to your computer and use it in GitHub Desktop.
automated theme switching for flluxbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# automate switching between dark and light themes in fluxbox. it currently | |
# changes themes of fluxbox, gtk2/3, tint2, hexchat and liferea. | |
declare -A BRIGHTNESS=( [light]=100 [dark]=0 ) | |
# declare -A BRIGHTNESS=( [light]=4 [dark]=6 ) | |
declare -A VSCODE_THEME=( | |
[light]="Atom One Light" | |
[dark]="Atom One Dark" | |
) | |
usage () { | |
cat << EOF | |
Switch desktop to dark or light theme. | |
Usage: ${0##*/} [-v|--verbose] [-h|--help] [-d|--dark|-l|--light] or dark/light | |
-v --verbose enable logging. | |
-h --help show this help. | |
-d --dark switch to dark style | |
-l --light switch to light style | |
There is no magic involved. You have to modifiy this script, to match your | |
desired styles and themes. | |
Use cron or redshift to automate theme switching. | |
EOF | |
} | |
# use: log && echo "write something to stdout" | |
l=1; log () { return $l; } | |
die () { | |
printf '%s\n\n' "$1" >&2 | |
usage | |
exit 1 | |
} | |
# is running | |
R () { | |
pidof $1 > /dev/null | |
return $? | |
} | |
# this is for gsettings | |
uid=$(id -u) | |
export DISPLAY=:0 | |
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$uid/bus" | |
# make sure gnome-settings-daemon is running | |
R gnome-settings-daemon || gnome-settings-daemon &> /dev/null & | |
reloadGTK () { | |
python - <<EOF | |
import gtk | |
events=gtk.gdk.Event(gtk.gdk.CLIENT_EVENT) | |
data=gtk.gdk.atom_intern("_GTK_READ_RCFILES", False) | |
events.data_format=8 | |
events.send_event=True | |
events.message_type=data | |
events.send_clientmessage_toall() | |
EOF | |
} | |
# common actions before switching | |
before () { | |
ret=1 | |
cur=$(grep gtk-application-prefer-dark ~/.config/gtk-3.0/settings.ini| sed 's/.*= *//g') | |
if [[ ( $cur = 1 && $1 = dark ) || ( $cur = 0 && $1 = light ) ]]; then | |
log && echo -e "$(date +'%a %h %e %H:%M:%S') $1 (doing nothing)" | |
else | |
ret=0 | |
fi | |
return $ret | |
} | |
# define some light switch actions here | |
light () { | |
# gsettings can't change this value, but it's useful for plugins (e.g. in atom and chrome) | |
sed -i -r 's/(\s*gtk-application-prefer-dark-theme\s*=\s*)(.+)/\10/g' ~/.config/gtk-3.0/settings.ini | |
} | |
# define some dark switch actions here | |
dark () { | |
sed -i -r 's/(\s*gtk-application-prefer-dark-theme\s*=\s*)(.+)/\11/g' ~/.config/gtk-3.0/settings.ini | |
} | |
# common actions after switching | |
after () { | |
log && echo -e "$(date +'%a %h %e %H:%M:%S') $1" | |
# set display brightness | |
# until sudo ddccontrol -r 0x10 -w ${BRIGHTNESS[$1]} dev:/dev/i2c-4 2>/dev/null|tail -1|grep "+/${BRIGHTNESS[$1]}/100" > /dev/null ; do sleep 0.1; done | |
# until sudo ddccontrol -r 0xdc -w ${BRIGHTNESS[$1]} dev:/dev/i2c-4 2>/dev/null|tail -1|grep "+/${BRIGHTNESS[$1]}/7" > /dev/null; do sleep 0.1; done; | |
# ~/.bin/sabr -b ${BRIGHTNESS[$1]} | |
# fluxbox style, reloadstyle fixes issues with style setting | |
fluxbox-remote "setstyle ~/.fluxbox/styles/Flat Plat $1" | |
fluxbox-remote reloadstyle | |
# wallpapers | |
feh --bg-scale ~/Pictures/wallpapers/1920x1200/Debian\ $1.png | |
# feh --bg-fill ~/Pictures/wallpapers/1080x1920/Debian\ $1.png ~/Pictures/wallpapers/1920x1200/Debian\ $1.png ~/Pictures/wallpapers/1600x768/* | |
# feh --bg-fill "`shuf -n1 -e ~/Pictures/wallpapers.$1/1080x1920/*`" "`shuf -n1 -e ~/Pictures/wallpapers.$1/1920x1200/*`" "`shuf -n1 -e ~/Pictures/wallpapers.$1/1600x768/*`" | |
echo -e "$(cat ~/.fehbg | tail -n +2)\n$(cat ~/.fehbg.hist|head -n 4)" > ~/.fehbg.hist | |
# xfce4-terminal | |
cp ~/.config/xfce4/terminal/terminalrc.$1 ~/.config/xfce4/terminal/terminalrc | |
#conky | |
cp ~/.config/conky/statusbar.conf.$1 ~/.config/conky/statusbar.conf | |
cp ~/.config/conky/infopanel/conkyrc.$1 ~/.config/conky/infopanel/conkyrc | |
# gtk2 | |
cp ~/.gtkrc-2.0.$1 ~/.gtkrc-2.0 | |
reloadGTK | |
# gtk3 (needs gnome-settings-daemon) | |
gsettings set org.gnome.desktop.interface icon-theme acyls-$1 | |
gsettings set org.gnome.desktop.interface gtk-theme Flat-Plat-$1-compact | |
# tint2 | |
cp ~/.config/tint2/tint2rc.$1 ~/.config/tint2/tint2rc | |
killall -SIGUSR1 tint2 | |
# hexchat (this is a custom build, there's no reloadstyle in regular hexchat) | |
cp ~/.config/hexchat/colors_flat_$1.conf ~/.config/hexchat/colors.conf | |
R hexchat && hexchat -e -c "gui reloadcolors" | |
# xrdb (xterm and others) | |
cp ~/.Xresources.$1 ~/.Xresources && xrdb ~/.Xresources | |
# vscode | |
sed -i -r "s/(\"workbench\.colorTheme\": \")(.+)/\1${VSCODE_THEME[$1]}\",/g" ~/.config/Code/User/settings.json | |
#tmux | |
cp ~/.tmux.conf.$1 ~/.tmux.conf && R tmux && tmux source-file ~/.tmux.conf | |
} | |
while :; do | |
case $1 in | |
-h|-\?|--help) | |
usage | |
exit | |
;; | |
-v|--verbose) | |
l=0 | |
;; | |
-l|--light|light) | |
before light && light && after light | |
break | |
;; | |
-d|--dark|dark) | |
before dark && dark && after dark | |
break | |
;; | |
-?*) | |
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2 | |
;; | |
?*) | |
die "ERROR: Unknown argument: \"$1\" (expected dark or light)" | |
break | |
;; | |
*) | |
die "ERROR: Missing argument, append \"dark\" or \"light\"." | |
break | |
;; | |
esac | |
shift | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* file: ~/.atom/init.js | |
* desc: watches ~/.config/gtk-3.0/settings.ini for changes in gtk-application-prefer-dark-theme | |
* and switches atom themes accordingly. | |
*/ | |
const fs = require('fs') | |
const path = require('path') | |
const home = require('os').homedir() | |
const gtk3dir = path.join(home, '.config/gtk-3.0') | |
const gtk3file = path.join(gtk3dir, 'settings.ini') | |
let currentMode = '' | |
const updateTheme = debounce(function() { | |
fs.readFile(gtk3file, (err, gtk3upd) => { | |
if (err) return; | |
const newMode = decode(gtk3upd.toString()).Settings['gtk-application-prefer-dark-theme']; | |
if (newMode !== currentMode) { | |
currentMode = newMode | |
atom.config.settings.core.themes = atom.themes.getActiveThemeNames().map(name => name.replace(/(dark|light)/, currentMode==='0'?'light':'dark')); | |
atom.themes.activateThemes(); | |
} | |
}) | |
}, 100) | |
fs.watch(gtk3dir, (a,b)=>{ | |
if(b!=='settings.ini') return | |
updateTheme() | |
}) | |
setTimeout(updateTheme, 15e3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# file: ~/.config/redshift/hooks/themeswitch.sh | |
# desc: call themeswitch on reshift events | |
case $1 in | |
period-changed) | |
case $3 in | |
night) | |
exec ~/.bin/themeswitch dark | |
;; | |
daytime) | |
exec ~/.bin/themeswitch light | |
;; | |
esac | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment