Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update-Link mega PR: Update to PR #22, closes issues #18, #19, #20 #23

Merged
merged 8 commits into from
Jun 27, 2017
508 changes: 508 additions & 0 deletions Get-Link.ps1

Large diffs are not rendered by default.

43 changes: 34 additions & 9 deletions Out-Colors.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,36 @@ $PalletSolarized = @{} # Will be used to invert the mapping

Write-Host

# Try and use the default background color to identify the installed theme
$BackgroundColor = switch ($HOST.UI.RawUI.BackgroundColor.ToString()) {
'DarkMagenta' {'DarkMagenta'} # None
'White' {'Gray'} # Light
'Black' {'DarkGray'} # Dark
# Try and use the default foreground and background color to identify the installed theme.
# Since the color names don't necessarily represent the actual color, this isn't a
# precise way to do this, but it works for the 4 most common cases.
# CMD: Gray/Black
# PowerShell: DarkYellow/DarkMagenta
# Solarized Light: DarkYellow/White
# Solarized Dark: DarkBlue/Black
$ForegroundColor = $HOST.UI.RawUI.ForegroundColor.ToString()
$BackgroundColor = $HOST.UI.RawUI.BackgroundColor.ToString()

if ($ForegroundColor -eq 'Gray' -and $BackgroundColor -eq 'Black') {
# CMD
$ForegroundColor = 'White'
$BackgroundColor = 'DarkGray'
} elseif ($ForegroundColor -eq 'DarkYellow' -and $BackgroundColor -eq 'DarkMagenta') {
# PowerShell default
$ForegroundColor = 'White'
$BackgroundColor = 'Blue'
} elseif ($ForegroundColor -eq 'DarkYellow' -and $BackgroundColor -eq 'White') {
# Solarized Light
$ForegroundColor = 'DarkGreen'
$BackgroundColor = 'Gray'
} elseif ($ForegroundColor -eq 'DarkBlue' -and $BackgroundColor -eq 'Black') {
# Solarized Dark
$ForegroundColor = 'DarkCyan'
$BackgroundColor = 'DarkGray'
}

# Draw table of Solarized mappings
Write-Host ("{0,-15} | {1,-15} | {2,-15}" -f "Solarized", "Light", "Dark") -BackgroundColor $BackgroundColor
Write-Host ("{0,-15} | {1,-15} | {2,-15} " -f "Solarized", "Light", "Dark") -BackgroundColor $BackgroundColor
$SolarizedPallet.keys | `
ForEach-Object {
Write-Host ("{0,-15}" -f $_) -BackgroundColor $BackgroundColor -NoNewline
Expand All @@ -40,19 +61,21 @@ $SolarizedPallet.keys | `
-ForegroundColor $SolarizedPallet[$_] `
-BackgroundColor 'White'
Write-Host (" | " -f $_) -BackgroundColor $BackgroundColor -NoNewline
Write-Host ("{0,-15}" -f $SolarizedPallet[$_]) `
Write-Host ("{0,-15}" -f $SolarizedPallet[$_]) -NoNewline `
-ForegroundColor $SolarizedPallet[$_] `
-BackgroundColor 'Black'
Write-Host (" " -f $_) -BackgroundColor $BackgroundColor

$PalletSolarized.Add($SolarizedPallet[$_], $_) # Create the inverted map
}
Write-Host (" "*53) -BackgroundColor $BackgroundColor

Write-Host

$Colors = [Enum]::GetValues( [System.ConsoleColor] )

# Draw table of ColorTable mappings
Write-Host ("{0,-15} | {1,-15} | {2,-15}" -f "Color Table", "Light", "Dark") -BackgroundColor $BackgroundColor
Write-Host ("{0,-15} | {1,-15} | {2,-15} " -f "Color Table", "Light", "Dark") -BackgroundColor $BackgroundColor
$Colors | `
ForEach-Object {$i=0}{
Write-Host ("{0,-11} [{1:X}]" -f $_.ToString(), $i++) -BackgroundColor $BackgroundColor -NoNewline
Expand All @@ -61,9 +84,11 @@ $Colors | `
-ForegroundColor $_.ToString() `
-BackgroundColor 'White'
Write-Host (" | " -f $_.ToString()) -BackgroundColor $BackgroundColor -NoNewline
Write-Host ("{0,-15}" -f $PalletSolarized[$_.ToString()]) `
Write-Host ("{0,-15}" -f $PalletSolarized[$_.ToString()]) -NoNewline `
-ForegroundColor $_.ToString() `
-BackgroundColor 'Black'
Write-Host (" " -f $_.ToString()) -BackgroundColor $BackgroundColor
}
Write-Host (" "*53) -BackgroundColor $BackgroundColor

Write-Host
Binary file added PowerShell-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PowerShell-default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PowerShell-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 74 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Solarized - Command Prompt theme
=============================================

This is a [Solarized][1] color scheme for the Windows command prompt,
with major contributions by Neil Pankey and Ryan Beesley.
with contributions by Neil Pankey, Ryan Beesley, Scott Hanselman,
Russell West, and Paul Hampson.

See the [Solarized home page][1] for screenshots and more details,
as well as color schemes for other applications. To contribute or file bug
Expand All @@ -11,8 +12,8 @@ or the main [Solarized repository][3].

Inspired by this [post][4]

Making Solarized work for cmd.exe, Bash on Ubuntu on Windows, and PowerShell,
and striking a balance with how other Solarized projects are implemented
Making Solarized work for cmd.exe, Bash on Ubuntu on Windows, and PowerShell,
and striking a balance with how other Solarized projects are implemented
presents some challenges. The following table shows how the colors are mapped.

| SOLARIZED | HEX | ANSI | TERMCOL | cmd.exe | PowerShell | ColorTable | DWORD |
Expand All @@ -34,58 +35,107 @@ presents some challenges. The following table shows how the colors are mapped.
| cyan | #2aa198 | ESC[1;36m | cyan | LightAqua | Cyan | 11 | 0098a12a |
| green | #859900 | ESC[1;32m | green | LightGreen | Green | 10 | 00009985 |

To make sure that the terminal is likely to use the best matching, the
ColorTable is aligned with TERMCOL values. These values were pulled from PuTTY
and other Solarized terminal profiles. This allows the same ANSI escape
sequences to show the same in ANSI supported terminals. The PowerShell default
colors are also matched for the $Host.PrivateData and PSReadLine to make them
To make sure that the terminal is likely to use the best matching, the
ColorTable is aligned with TERMCOL values. These values were pulled from PuTTY
and other Solarized terminal profiles. This allows the same ANSI escape
sequences to show the same in ANSI supported terminals. The PowerShell default
colors are also matched for the $Host.PrivateData and PSReadLine to make them
seemingly fit with the rest of the environments.

WARNING
-------

Below are very simplified installation instructions. It **will not** update
existing shortcuts because they have their own color mapping. It **will not**
always play nice with traditional unix tools or compatability shims because
Windows uses a fundamentally different color code mapping.
Below are very simplified installation instructions. ~~It **will not** update
existing shortcuts because they have their own color mapping.~~ With this
latest version of the project, it is possible to apply to existing shortcuts,
but it **will not** be easy to revert that change. It **will not** always play
nice with traditional unix tools or compatability shims because Windows uses a
fundamentally different color code mapping.

Installation
------------

### Update Registry for Console
While this was the original process, this only changes the registry default
and doesn't update the Command Prompt and PowerShell defaults when you launch
those shortcuts. It is still something you may wish to do, but the recommended
process is now to use the Update-Link utility.

Import the `.reg` file of choice, e.g. `regedit /s solarized-dark.reg`.

Both files contain the same palettes, the only difference is the default
foreground and background colors. Therefore you can switch between themes on
the fly with `color 01` for dark and `color F6` for light.

Copy the `Set-Solarized*ColorDefaults.ps1` files to your profile directory,
likely `~\Documents\WindowsPowerShell\`. Then add the following line of code
### Update Command Prompt and PowerShell shortcut .lnks
Locate the link you wish to modify, such as Command Prompt. The easiest way to
do this on Windows 10 is to click `Start`, then type in the command you want to
change. When it appears in the list, right-click and select `Open file
location`. This will open an Explorer window and show you the shortcut. Hold
shift and right-click on the shortcut, then select `Copy as path`. Now open a
Command Prompt to the location of this project. In the Command Prompt window
use this command.

Update-Link "<shortcut.lnk>" [dark|light]

The path to the shortcut.lnk is the same as you copied to your clipboard in the
previous step. To easily paste it in Windows 10, just right-click on the
window. If the path has spaces, you will want to wrap it in quotes, but if you
followed the recommended way to use `Copy as path`, it will be done for you. If
no theme is given, `Update-Link` will default to Solarized Dark.

### Update your PowerShell profile
Copy the `Set-Solarized*ColorDefaults.ps1` files to your profile directory,
likely `~\Documents\WindowsPowerShell\`. Then add the following line of code
to the end of your `Microsoft.PowerShell_profile.ps1` or `profile.ps1`:

. (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}}))

Uninstall
------------

The file `windows-defaults.reg` is provided to restore the command prompt
colors back to their shipping defaults. The registry settings have been
checked for versions of Windows back to at least Windows 7 and the values are
### Registry for Console
The file `windows-defaults.reg` is provided to restore the command prompt
colors back to their shipping defaults. The registry settings have been
checked for versions of Windows back to at least Windows 7 and the values are
the same.

To restore the defaults, import the `.reg` the same way as you applied it
previously, `regedit /s windows-defaults.reg`. You will also want to revert
any changes you made to your PowerShell profile.
To restore the defaults, import the `.reg` the same way as you applied it
previously, `regedit /s windows-defaults.reg`.

### Command Prompt and PowerShell shortcut .lnks
Unfortunately, this is not the easiest to revert right now. One way, which is
not recommended for casual users is to edit the `Properties` of an open window.
From there, you can edit the colors manually, using the table as a guide. If
there is enough interest and demand, a future update may make it possible to
apply other themes using the `Update-Link` utility, but for now it is not very
easy to revert.

### PowerShell profile
You will also want to revert any changes you made to your PowerShell profile.
Just open the profile you created or modified and remove the code.

Screenshots
------------

![Dark prompt][5]
### PowerShell Light
![PowerShell Light prompt][5]

### PowerShell Dark
![PowerShell Dark prompt][6]

And for comparison purposes:
### PowerShell Default
![PowerShell Default prompt][7]

![Light prompt][6]
### Command Prompt Default
![Command Prompt Default prompt][8]

[1]: http://ethanschoonover.com/solarized
[2]: https://github.com/neilpa/cmd-colors-solarized
[3]: https://github.com/altercation/solarized
[4]: https://github.com/altercation/solarized/issues/127
[5]: https://raw.github.com/neilpa/cmd-colors-solarized/master/cmd-dark.png
[6]: https://raw.github.com/neilpa/cmd-colors-solarized/master/cmd-light.png
[5]: https://raw.github.com/neilpa/cmd-colors-solarized/master/PowerShell-light.png
[6]: https://raw.github.com/neilpa/cmd-colors-solarized/master/PowerShell-dark.png
[7]: https://raw.github.com/neilpa/cmd-colors-solarized/master/PowerShell-default.png
[8]: https://raw.github.com/neilpa/cmd-colors-solarized/master/cmd-default.png
2 changes: 2 additions & 0 deletions Update-Link.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@ECHO OFF
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dpn0.ps1" %*
46 changes: 46 additions & 0 deletions Update-Link.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
param(
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path $_})]
[string]$Path,

[Parameter()]
[ValidateSet('Light','Dark')]
[string]$Theme = 'Dark'
)

$lnk = & ("$PSScriptRoot\Get-Link.ps1") $Path

# Set Common Solarized Colors
$lnk.ConsoleColors[0]="#002b36"
$lnk.ConsoleColors[8]="#073642"
$lnk.ConsoleColors[2]="#586e75"
$lnk.ConsoleColors[6]="#657b83"
$lnk.ConsoleColors[1]="#839496"
$lnk.ConsoleColors[3]="#93a1a1"
$lnk.ConsoleColors[7]="#eee8d5"
$lnk.ConsoleColors[15]="#fdf6e3"
$lnk.ConsoleColors[14]="#b58900"
$lnk.ConsoleColors[4]="#cb4b16"
$lnk.ConsoleColors[12]="#dc322f"
$lnk.ConsoleColors[13]="#d33682"
$lnk.ConsoleColors[5]="#6c71c4"
$lnk.ConsoleColors[9]="#268bd2"
$lnk.ConsoleColors[11]="#2aa198"
$lnk.ConsoleColors[10]="#859900"

# Set Light/Dark Theme-Specific Colors
if ($Theme -eq "Dark") {
$lnk.PopUpBackgroundColor=0xf
$lnk.PopUpTextColor=0x6
$lnk.ScreenBackgroundColor=0x0
$lnk.ScreenTextColor=0x1
} else {
$lnk.PopUpBackgroundColor=0x0
$lnk.PopUpTextColor=0x1
$lnk.ScreenBackgroundColor=0xf
$lnk.ScreenTextColor=0x6
}

$lnk.Save()

Write-Host "Updated $Path to Solarized - $Theme"
Binary file removed cmd-dark.png
Binary file not shown.
Binary file modified cmd-default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed cmd-light.png
Binary file not shown.