1
0
Fork 0
env/.local/bin/mode

85 lines
2.0 KiB
Bash
Executable File

#!/bin/zsh
MODE_DEFAULT=('default.jpg' 'true' 'Solarized Matched' 'Dark Matched' 'df202020' 'ff999999')
MODE_DARK=('dark.png' 'true' 'Solarized Matched' 'Dark Matched' '00202020' 'ff999999')
MODE_LIGHT=('light.png' 'false' 'Solarized Light Matched' 'Light Matched' '00dfdfdf' 'ff666666')
evaluate() {
input="$1"
shift
replacements=($@)
for i in {1..$#replacements}; do
match="{$i}"
replacement="${replacements[i]}"
input="$(echo "$input" | sed "s/$match/$replacement/g")"
done
echo $input
}
change_system_theme() {
mode=($@)
rm -f ~/Pictures/wallpapers/current/*
cp ~/.wallpaper/"${mode[1]}" ~/Pictures/wallpapers/current/"${mode[3]}${mode[1]}"
template="
tell application \"System Events\"
tell desktops
set change interval to -1
set change interval to 1
end tell
tell appearance preferences
set dark mode to {2}
end tell
end tell
"
osascript -e "$(evaluate "$template" $mode)"
}
change_iterm2_theme() {
mode=($@)
template='
import iterm2
async def main(conn):
app = await iterm2.async_get_app(conn)
profiles = await iterm2.PartialProfile.async_query(conn)
new_profile = None
for profile in profiles:
if profile.name == "{3}":
new_profile = await profile.async_get_full_profile()
await profile.async_make_default()
windows = app.terminal_windows
for window in windows:
tabs = window.tabs
for tab in tabs:
sessions = tab.sessions
for session in sessions:
await session.async_set_profile(new_profile)
iterm2.run_until_complete(main)
'
script="$HOME/Library/Application Support/iTerm2/Scripts/change-theme.py"
evaluate "$template" $mode > $script
python3 $script
}
change_yabai_theme() {
mode=($@)
yabai -m config status_bar_background_color 0x${mode[5]}
yabai -m config status_bar_foreground_color 0x${mode[6]}
}
mode_name="MODE_$1:u"
mode=(${(P)mode_name})
if [[ -z $mode ]]; then
echo "No mode specified"
exit 1
fi
change_system_theme $mode
change_iterm2_theme $mode
change_yabai_theme $mode