Wednesday, July 17, 2013

PowerGUI Syntax Highlighting

If you do any scripting in PowerShell, allow me to strongly recommend that you check out PowerGUI. It's exceptionally handy, and pretty tweakable.

After reading Jason Slaughter's TechNet Blog post on Exchange ActiveSync logging via PowerShell, I realized that I wasn't satisfied with the default syntax highlighting in PowerShell, and went on a quest to find out how to improve it. As it turns out, I wasn't able to find much on the topic online. The PowerGUI wiki mentions that it's possible to change via an XML file, but doesn't go into much more detail than that. Adam at CSharpening.net has a blog post with the results of his foray into the topic, which also pointed me to the list of named colors that could be used, which came in handy.

Using this as a foundation, I got to work.

First, a couple of quick notes. In order to save your changes to the PowerShellSyntax,xml file, you're going to have to open it with elevated rights. Also, these changes don't take effect immediately, so you're going to have to close and re-open PowerGUI each time you make changes in order to see their effects.

As I worked through the different styles, I realized that I actually wasn't sure when some of them were supposed to be applied, so I wrote a syntax test script with examples of each type, and a block at the bottom that lists the strings that trip each type. You can snag it from GitHub.

One of the first things I noticed when working my way through the XML was that the AutoVars style was not used anywhere. There's a PSAutoVars group defined, but it uses the VariableStyle style. I changed that, since a separate highlighting style makes sense for these variables:

Find:
<ExplicitPatternGroup TokenKey="PSAutoVars" TokenID="23" Style="VariableStyle" LookAhead="{NonWordMacro}|\z" CaseSensitivity="AutoCorrect">

Replace with:
<ExplicitPatternGroup TokenKey="PSAutoVars" TokenID="23" Style="AutoVars" LookAhead="{NonWordMacro}|\z" CaseSensitivity="AutoCorrect">

In the list below that line, I also added $true and $false, since those are also built-in variables that I wanted highlighted using this style.

That done, I messed with styles themselves. Here's what I finally settled on:
<!-- Highlighting Styles -->  <Styles>    <Style Key="ReservedWordStyle" ForeColor="Blue" Italic="True" />    <Style Key="OperatorStyle" ForeColor="Red" />    <Style Key="OperatorWordStyle" ForeColor="Red" />    <Style Key="VariableStyle" ForeColor="DarkSlateGray" Bold="True" />    <Style Key="CmdletStyle" ForeColor="Blue" />    <Style Key="NetClassStaticStyle" ForeColor="teal" />    <Style Key="NetClassStaticMethodStyle" ForeColor="saddlebrown" />    <Style Key="CmdletParamStyle" ForeColor="Navy" />    <Style Key="NumberStyle" ForeColor="Black" />    <Style Key="StringDelimiterStyle" ForeColor="Purple" />    <Style Key="StringDefaultStyle" ForeColor="Purple" Italic="True" />    <Style Key="CommentDelimiterStyle" ForeColor="Green" />    <Style Key="CommentDefaultStyle" ForeColor="Green" />    <Style Key="AutoVars" ForeColor="DarkOrange" Bold="True"/>    <Style Key="FunctionStyle" ForeColor="CadetBlue" />  </Styles>


And a side-by-side for ya:






Thursday, January 17, 2013

Quick Send in Gmail's new Compose window

If you're an Outlook user at work (like myself), this may make you very very happy.

In Outlook, you see, when composing an email, the Ctrl+Enter hotkey can be used to send the message without having to move your hand to your mouse and click Send1. If this is the first you've heard of it, give it a try the next time you compose an email, and you'll probably be addicted.

This is such a natural and simple operation to me that I found myself doing it in Gmail without thinking. Sadly, in the early days of Gmail, no such shortcut existed. I could press Tab, then Enter instead, which was a perfectly workable substitute, with the sole downside of having to remember one shortcut for one application and another for a different one.

Recently, Gmail updated to a new compose interface to allow us to write messages while still viewing our Inbox. Brilliant! I've been using it since it was first offered on an opt-in basis, and I love it.

Today, I loved it even more. I opened a new message, finished writing it, and pressed Ctrl+Enter out of habit... and the message sent!

As a fervent advocate of hotkeys, I've heard numerous people complain that learning this series of hotkeys for this app and that series for that app that does the same thing was just too hard. I have no rebuttal for that - I tend to agree, though I still find the use of hotkeys to be something that saves me hours of time and focus, so I will still slog through attempts to learn them.

I'm glad to see Google adopting hotkeys like this one from software that's already familiar to their users. It will make everyone's lives easier, in the long run.


[1] - As will become rapidly apparent in my postings here, I'm a huge fan of keyboard shortcuts over mouse movements. If this seems like an insignificant thing, think about how often you have to take a hand off of the keyboard, move it to your mouse, select a new field or window, then remove that hand from the mouse and move it back to your keyboard so you can resume typing. If you don't feel that that happens often, rock on!

If - on the other hand - you have just come to the realization that you are frequently wasting time, energy, and focus on a circular motion that, in many cases, can be replaced by pressing a key (or a combination thereof), you are in the same boat as the vast majority of computer users.