More fun with prompts

Here’s some more fun you can have with your PowerShell prompt. Hopefully you caught my earlier post on this topic. Let’s continue. One thing you may not realize about Powershell, is that the native format is Unicode. This means you can display Unicode characters in your prompt.

To display a Unicode character you need to know its code number. Open Character Map (Start – Run – Charmap).  As you hover your mouse over a character you will see something like U+0040. That is the code number.  To use that number in PowerShell type

PS C:\> [char]0x0040

What you’re doing is replacing U+ with 0x so that you’ve typed a hex value.

You should get the @ symbol. Big deal.  I can type the character from the keyboard. But there are many other characters you can use that aren’t on the keyboard.  Try these expressions out:

PS C:\> [char]0x00b6

PS C:\> [char]0x25ba

PS C:\> [char]0x25c4

PS C:\> [char]0x25bc

PS C:\> [char]0x25b2

Do you see where I’m going with this? Now you can have a prompt that has a little something extra like this:

Function prompt {
#PSH S:\PoSH <green right pointing triangle>
Write-Host “PSH $(get-location) ” -nonewline -fore yellow
Write-Host ([char]0x25ba) -fore Green -nonewline
Return ” “
 }

This will give you a prompt like this:

PSH J:\WindowsPowerShell

(The color doesn’t display nicely, sorry.)

With Unicode I can draw boxes so what about displaying a prompt like this:

┌────────────────────────────────────────────┐
│PSH 6/8/2007 1:19 PM J:\WindowsPowerShell >                             │
└────────────────────────────────────────────┘->

The formatting is a little off when copied here, but you get the idea. I’ve attached the functions so you don’t have to try and copy.  I’ve got one more major prompt idea but I’ll save that for later.

del.icio.us Tags: , , ,