Tuesday, March 25, 2014

Introducing the New ISE Color Theme Cmdlets!

Last week I posted about the ability to theme the Powershell ISE script pane and provided a link to a few themes to play with. In that article I lamented about the lack of command line support for themes. Allow me to elaborate a little. You can certainly change any theme element from the command line but you can not do the following:

  • Apply a theme to your ISE session from a file or from a previously saved ISE theme
  • Import an xml theme to the ISE
  • Export an ISE theme to an xml file

Worse yet, the color values stored in the theme xml files are ARGB based, not hex, which is what you need to apply a theme color to an ISE property from the command line. For this reason the scripts used to apply themes are completely different than the xml files used for the import/export process. How could Microsoft come so far, yet come up so short?! Frustrating to say the least!

Solution

Where there is a problem, there is opportunity! After reviewing the situation and coming to the conclusion that all the pieces I needed were there, I decided to create the ISE Theme Cmdlets script module. This script module allows you to do all of the above and more from the command line. 

Here are a few things you can do with these cmdlets:
  • Batch import a collection of xml theme files
  • Batch export all of the custom themes available in the ISE
  • Choose a different custom theme from the command line
  • Alter the overall color scheme of a theme without the need to tweak each parameter individually

This last bullet point or feature is a lot of fun! The Adjust-ISEColor cmdlet allows you to easily alter a theme by giving it the following commands:
  • Cooler
  • Warmer
  • Greener
  • Lighter
  • Darker
This cmdlet also uses a "Degree" parameter to set the degree of change to make. By playing with this cmdlet I was able to generate all of the new themes attached below in a fraction of the time it would take with the default interface. Give it a try and share your work!

ISEThemeCmdlets

Here is the list of cmdlets with a short description and example. 

Get-FileName()
Gets a file name using an OpenFileDialog.
Get-FileName | Set-ISETheme 


Get-SaveFile()
Gets a save file name using a SaveFileDialog.
$File = Get-SaveFile


Convert-HexToARGB()
Converts Hex to ARGB values
$ARGB = Convert-HexToARGB #FF000022


Convert-ARGBToHex()
Converts ARGB to Hex values
$Hex = Convert-ARGBToHex "255,0,0,233"


Get-CurrentISETheme()
Gets current ISE theme. Hex colors are converted to ARGB and added back to the returned objects
$CurrentISETheme = Get-CurrentISETheme


Get-ISETheme()
Gets an ISE them from either the ISE or xml file
$Theme = Get-FileName | Get-ISETheme


Get-ImportedISEThemes()
Returns imported theme objects from the ISE
$Themes = Get-ImportedISEThemes


Set-ISETheme()
Applies ISE theme to current session
Get-FileName | Set-ISETheme


Import-ISEThemeFile()
Imports an ISE theme xml file into the ISE and applies it to the current session if ApplyTheme is passed
Get-ChildItem d:\sandbox -Include *.ps1xml -recurse | Import-ISEThemeFile -ApplyTheme


Export-ISEThemeFile()
Exports an ISE theme to an xml file and saves it into the ISE if SaveToISE is passed
Export-ISEThemeFile -SaveToISE


Remove-ISETheme()
Deletes an ISE theme from the ISE
Remove-ISETheme "Monokai"


Adjust-ISEColor()
Adjusts ISE Theme colors according to switch
Set-ISEThemeWarmth -Cooler


Select-ISETheme()
Selects and applies an ISE theme using a selection form
Select-ISETheme


More Color Themes

Last week I shared a collection of themes I found in various searches online. This week I'm happy to say the themes I'm sharing are all original and created using the ISE Color Theme Cmdlets!

Here they are:



Brownie




Aquatic



Nightvale



PaperRose





To batch import these new themes, extract them to your file system and run the following command:

gci "C:\YourThemes" -Filter *.ps1xml | Select FullName | Import-ISEThemeFile



Here is a link to the new PowerShell Color Themes

Here is a link to the ISE Color Theme Cmdlets


1 comment:

  1. In default dark theme of ISE #region syntax as kinda blending in with the background. Couldn't find a way to change #region color. Will this help me?

    ReplyDelete