Cmder 跟随 Windows 明暗主题
发表于|更新于
Cmder 本身不跟随系统主题;启动时由 user_profile.cmd 设置,运行中的窗口交给 AutoDarkMode 触发。
新标签:config/user_profile.cmd
1 2 3 4 5 6
| @echo off setlocal reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" /v AppsUseLightTheme 2>nul | %SystemRoot%\System32\findstr.exe /c:"0x1" >nul if errorlevel 1 (set "WB_SCHEME=<Tomorrow Night>") else (set "WB_SCHEME=<Tomorrow>") "%ConEmuDir%\ConEmu\ConEmuC64.exe" -GuiMacro SetOption Scheme "%WB_SCHEME%" endlocal
|
新开 cmd 标签时读取系统主题,设置当前 ConEmu 窗口配色。
运行中:AutoDarkMode/scripts.yaml
1 2 3 4 5 6 7 8 9 10
| Enabled: true Component: Scripts: - Name: Cmder Theme Command: C:\Windows\System32\cmd.exe WorkingDirectory: C:\app\Cmder ArgsLight: [/c, C:\Users\guojin\AppData\Roaming\AutoDarkMode\cmder-theme.cmd, light] ArgsDark: [/c, C:\Users\guojin\AppData\Roaming\AutoDarkMode\cmder-theme.cmd, dark] AllowedSources: [Any, TimeSwitchModule] TimeoutMillis: 10000
|
AutoDarkMode 在明暗切换时调用 helper,分别传 light / dark。
窗口切换:AutoDarkMode/cmder-theme.cmd
1 2 3 4 5 6 7 8 9 10 11
| @echo off setlocal if /i "%~1"=="dark" (set "SCHEME=<Tomorrow Night>") else (set "SCHEME=<Tomorrow>") for /f "tokens=2 delims=," %%p in ('%SystemRoot%\System32\tasklist.exe /fi "imagename eq ConEmu64.exe" /fo csv /nh 2^>nul ^| %SystemRoot%\System32\findstr.exe /i "ConEmu64"') do ( "C:\app\Cmder\vendor\conemu-maximus5\ConEmu\ConEmuC64.exe" -GUIMACRO:%%~p SetOption Scheme "%SCHEME%" ) for /f "tokens=2 delims=," %%p in ('%SystemRoot%\System32\tasklist.exe /fi "imagename eq ConEmu.exe" /fo csv /nh 2^>nul ^| %SystemRoot%\System32\findstr.exe /i "ConEmu.exe"') do ( "C:\app\Cmder\vendor\conemu-maximus5\ConEmu\ConEmuC.exe" -GUIMACRO:%%~p SetOption Scheme "%SCHEME%" ) endlocal exit /b 0
|
枚举运行中的 ConEmu 窗口,用 -GUIMACRO:<PID> 逐个切换配色。
配色名以 ConEmu 设置页为准:<Tomorrow> / <Tomorrow Night>;路径按自己环境替换。