Change wsl2 app themes based on Windows theme switch
- wsl2
- AutoDarkMode
- zsh (recommended)*
* May work with bash, to try, change the first line of adm.sh and functions.sh from:
#!/usr/bin/zshto
#!/usr/bin/bash- Configure the
scripts.yamlof AutoDarkMode:
Enabled: true
Component:
Scripts:
# Other scripts (if any)
- Name: autodarkmode_wsl
Command: powershell
ArgsLight: [-NoProfile, -Command, wsl path/to/repo/adm.sh 1]
ArgsDark: [-NoProfile, -Command, wsl path/to/repo/adm.sh 0]
AllowedSources: [Any]- Put the following in
~/.zprofileor$ZDOTDIR/.zprofile:
if [ -z $TMUX ]
then
path/to/repo/adm.sh
fiCurrently the script is configured for:
- wslg
- tmux
- neovim
- lazygit
- bat
- glow
** NOTE: You need to have your own configuration files for light and dark themes for each program.**
** You can add or modify paths of the config files in adm.sh.**
- To add more programs, add config files for that program to
adm.sh. - Use existing functions if theme switch can be done using linking config file to its dark or light variant.
- Otherwise, create new functions in functions.sh
- Call the function at the end of script with newly added program variable.
Assuming you have pygments installed,
- Copy your
ipythonprofile default theme (typically found in~/.ipython/profile_default/or~/.ipython/profile_$USER/directory) to a new file calledlight.pyin the same directory. - Change the following line to your preferred light theme (e.g.
'gruvbox-light')
c.TerminalInteractiveShell.highlighting_style = 'gruvbox-light'- Do the same process for dark, i.e. create dark.py and change
highlighting_styleto a dark theme. - In
adm.sh, add the following at the end of config section:
IPYTHON_CONFIG=(~/.ipython/profile_default/{ipython_config.py,light.py,dark.py})- Now based on system theme, light.py or dark.py can be linked to
config.py. A symlink can be created usinglinkconfigfunction fromfunctions.sh. Add the following line to the end ofadm.sh:
linkconfig "${IPYTHON_CONFIG[@]}" softCreates symbolic link, or hardlink, or copy based on argument
Based on WINTHEME, links to dark or light file.
This function takes three arguments,
- argument 1 is the path where the config file must be put.
- argument 2 path of the light themed configuration file.
- argument 3 path of the dark themed configuration file.
- argument 4
soft|hard|copysoft- Creates a soft (symbolic) link to the chosen theme as config filehard- Creates a hard link to the chosen theme as config filecopy- Creates a copy of the chosen theme file and saves as config file
Attempts to change the background of theme in running nvim instances.
If socket files with matching pattern exist, sends remote commands to instance.
In order for this to work, nvim must be started with a listen address.
e.g. nvim --listen /tmp/nvim_1234.sock, for a stable solution an alias
could be added in .zshrc:
alias nvim=nvim --listen /tmp/nvim_*.sockChanges wslg theme based on WINTHEME
Takes 1 argument:
- argument 1: Name of the theme (e.g.
Adwaita)
Possible values 0 or 1. 0 - Dark 1 - Light
When called without arguments, WINTHEME is set by checking windows registry value
of AppsUseLightTheme. NOTE: Querying the registry takes ~2 seconds. When called
with argument, WINTHEME is the value of the first argument. If provided argument
is not 0 or 1, query windows registry to set WINTHEME.
Possible values light or dark.
MODE can be used in cases where light or dark must be provided to change theme.