neilpa / cmd-colors-solarized

Solarized color settings for Windows command prompt
1.11k stars 177 forks source link

powershell.exe has default registry override for colours #18

Closed TBBle closed 7 years ago

TBBle commented 7 years ago

Repeating https://github.com/neilpa/cmd-colors-solarized/issues/14#issuecomment-282711792:

There's a registry key in HKEY_CURRENT_USER\Console for %SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe which contains entries overriding the registry setting you've imported.

You can either delete/rename those keys (PopupColors, ScreenColors and anything starting with ColorTable), or update them to match the registry file you chose (solarized-dark.reg or solarized-light.reg).

There's also (on a 64-bit system) a %SystemRoot%_SysWOW64_WindowsPowerShell_v1.0_powershell.exe key for the 32-bit powershell executable.

This shows up when the background and text colour of a powershell instance started by "Start->Run->powershell", i.e. not via a shortcut, is not affected by the registry file.

We probably need some way of addressing this, either in the documentation or with some kind of install script?

TonyApuzzo commented 7 years ago

I have to confess that I am totally confused by how the install is supposed to work for PowerShell, CMD, Windows bash, etc. on Windows 10. I installed the registry file and added the line to my $profile but nothing changed from what I can tell. Then I deleted the HKEY_CURRENT_USER\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe and HKEY_CURRENT_USER\Console\%SystemRoot%_SysWOW64_WindowsPowerShell_v1.0_powershell.exe and it still made no difference. Then after reading more about the start menu's powershell being different, I manually added my own shortcut for powershell using New->Shortcut->powershell.exe, when I launch from that icon I get a black background and the foreground color for arguments is dark blue which is terrible!

How is this supposed to work? The install instructions are either wrong or too terse. I ASSuMEd that once I installed the registry file I would start getting the updated colors, but maybe I have to run a ps1 file or something?

TBBle commented 7 years ago

@TonyApuzzo To be clear, did you copy the two Set-Solarised*ColorDefaults.ps1 files into %UserProfile%\Documents\WindowsPowerShell? The line added to your profile.ps1 executes one of those two files every time you start powershell.

TonyApuzzo commented 7 years ago

I did put the profile line in, but the profile doesn't actually do anything because $HOST.UI.RawUI.BackgroundColor.ToString() returns DarkMagenta on my system instead of Black or White.

When I manually run Set-SolarizedDarkColorDefaults.ps1 it does set some colors, but the contrast is totally messed up.

The reg files mention HKEY_CURRENT_USER so I'm loading the reg file as normal user, not admin.

I'm using the default branch in git, maybe there is a better branch?

PS U:\> $profile
C:\Users\tapuzzo\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

PS U:\> more $profile
. (Join-Path -Path (Split-Path -Parent -Path $PROFILE) -ChildPath $(switch($HOST.UI.RawUI.BackgroundColor.ToString()){'White'{'Set-SolarizedLightColorDefaults.ps1'}'Black'{'Set-SolarizedDarkColorDefaults.ps1'}default{return}}))

PS U:\> $HOST.UI.RawUI.BackgroundColor.ToString()
DarkMagenta

PS U:\projects\cmd-colors-solarized> dir $HOME\Documents\WindowsPowerShell\
    Directory: C:\Users\tapuzzo\Documents\WindowsPowerShell
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         6/5/2017  10:38 AM            231 Microsoft.PowerShell_profile.ps1
-a----         6/5/2017  10:27 AM           1991 Set-SolarizedDarkColorDefaults.ps1
-a----         6/5/2017  10:27 AM           1977 Set-SolarizedLightColorDefaults.ps1
TonyApuzzo commented 7 years ago

UPDATE: Loading the registry as 'admin' (or double-clicking on the file rather than running from the powershell command line) fixes my problem. Apparently my situation was cause by the registry file not being loaded correctly.

If I use the Windows search or right-click on the start window, I still get the blue/white stock theme, but if I run powershell from a new shortcut on the desktop then I get the solarized colors. So I think now I'm in the same situation as everyone else. If I run cmd from the windows start, it does have the solarized theme. Git Bash and Ubuntu-Bash-On-Windows retain their original theme colors.

TBBle commented 7 years ago

Yeah, the 'Windows Search' result "Windows PowerShell" is a shortcut, you can either fix it by hand (painful!) or wait for #19 to get done.

TBBle commented 7 years ago

Explanation of the registry keys can be found via https://github.com/neilpa/cmd-colors-solarized/issues/19#issuecomment-311493124.

The short answer is that they're loaded from and written to only if you don't run the program via a shortcut.

Since the documentation recommends only updating the Shortcuts, there's no strong motivation to add these keys to the documentation.

So closing this issue.

MJMultari commented 7 years ago

Created a new shortcut and everything works perfectly!