✨ add dark/light mode control from wsl
This commit is contained in:
parent
e3886bbc91
commit
7b9f231771
2 changed files with 70 additions and 14 deletions
52
bashscripts/wsl_theme.sh
Normal file
52
bashscripts/wsl_theme.sh
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
color_scheme=$1
|
||||||
|
|
||||||
|
# write a file with the current theme here:
|
||||||
|
nvim_color_theme_path=~/.local/share/nvim_color_scheme
|
||||||
|
|
||||||
|
# validate user input
|
||||||
|
if [[ "$color_scheme" != "dark" && "$color_scheme" != "light" ]]; then
|
||||||
|
echo "Error: Color scheme must be 'dark' or 'light'" >&2
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo $color_scheme > $nvim_color_theme_path
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check that all relevant files exist
|
||||||
|
windows_username=$(powershell.exe '$env:UserName' | tr -d '\r\n')
|
||||||
|
dark_mode_config_path=~/python-projects/24_alacritty_windows_setup/gruvbox_material_medium_dark.toml
|
||||||
|
light_mode_config_path=~/python-projects/24_alacritty_windows_setup/gruvbox_material_medium_light.toml
|
||||||
|
if [ ! -f $light_mode_config_path ]; then
|
||||||
|
echo "error: light_mode_config_path missing"
|
||||||
|
echo "expected: $light_mode_config_path"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f $dark_mode_config_path ]; then
|
||||||
|
echo "error: dark_mode_config_path missing"
|
||||||
|
echo "expected: $dark_mode_config_path"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
windows_alacritty_config_path="/mnt/c/Users/${windows_username}/AppData/Roaming/alacritty/alacritty.toml"
|
||||||
|
echo 'overwriting windows alacritty config'
|
||||||
|
|
||||||
|
if [ $color_scheme = 'dark' ]; then
|
||||||
|
echo "going dark"
|
||||||
|
cp $dark_mode_config_path $windows_alacritty_config_path
|
||||||
|
|
||||||
|
# explorer, browser etc
|
||||||
|
powershell.exe -Command "Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 0"
|
||||||
|
# taskbar and start menu
|
||||||
|
powershell.exe -Command "Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -Value 0"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $color_scheme = 'light' ]; then
|
||||||
|
echo "going light"
|
||||||
|
cp $light_mode_config_path $windows_alacritty_config_path
|
||||||
|
|
||||||
|
# explorer, browser etc
|
||||||
|
powershell.exe -Command "Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 1"
|
||||||
|
# taskbar and start menu
|
||||||
|
powershell.exe -Command "Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -Value 1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
@ -13,20 +13,24 @@
|
||||||
set nohlsearch
|
set nohlsearch
|
||||||
|
|
||||||
lua << EOF
|
lua << EOF
|
||||||
local hkey_current_user_path = 'HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize'
|
local config_file = os.getenv("HOME")..'/.local/share/nvim_color_scheme'
|
||||||
local ps_cmd = 'Get-ItemProperty -Path ' .. hkey_current_user_path .. ' -Name AppsUseLightTheme'
|
local f=io.open(config_file, "r")
|
||||||
local parent_cmd = 'powershell.exe -Command "' .. ps_cmd .. '"'
|
if f~=nil then
|
||||||
local handle = io.popen(parent_cmd)
|
local system_theme = f:read()
|
||||||
local result = handle:read("*a")
|
-- f:close()
|
||||||
handle:close()
|
io.close(f)
|
||||||
local apps_use_light_theme = string.match(result, "AppsUseLightTheme%s*:%s*(%d+)")
|
if system_theme == 'dark' then
|
||||||
local use_dark_bg = apps_use_light_theme == '0'
|
vim.cmd("set bg=dark")
|
||||||
print('use dark:', use_dark_bg)
|
elseif system_theme == 'light' then
|
||||||
|
vim.cmd("set bg=light")
|
||||||
if use_dark_bg then
|
else
|
||||||
vim.cmd("set bg=dark")
|
print('warning: expected value "light" or "dark"')
|
||||||
|
print(' got:', system_theme)
|
||||||
|
print(' expected path:', file)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
vim.cmd("set bg=light")
|
print('warning: nvim color scheme not found')
|
||||||
|
print(' expected path:', file)
|
||||||
end
|
end
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue