Montag, 29. Dezember 2008

ISE - Comment out a block of text

Here the final code using #-comments:

function ISE-CommentOut () {
$text = $psise.CurrentOpenedFile.editor.SelectedText
$lines = $text.Split("`n") |% {
$_ -replace "^", "# "
if ($lines[$lines.count -1] -eq "# "){
$lines[$lines.count -1] = ""
$text = [string]::join("`n", $lines)

function ISE-CommentIn () {
$text = $psise.CurrentOpenedFile.editor.SelectedText
$lines = $text.Split("`n") |% {
$_ -replace "^ *# *", ""
$text = [string]::join("`n", $lines)

$psIse.CustomMenu.Submenus.Add("Comment Out", {ISE-CommentOut}, "Ctrl+K")
$psIse.CustomMenu.Submenus.Add("Comment In", {ISE-CommentIn}, "Ctrl+SHift+K")

ISE - BlockComment BlockUncomment custom menue

Hello everyone,

based on ideas from Andy Schneider I played a little to supply custom menues to ISE for commenting out blocks and removing comments:

function ISE-BlockCommentOut () {
$text = $psise.CurrentOpenedFile.editor.SelectedText
$text = $text -replace "#>", "# >"
$text = $text -replace "<#", "< #"
$text = "<#`n$text`n#>"
#$text = $text -replace "(^|\n)", "$1# "

function ISE-BlockCommentIn () {
$text = $psise.CurrentOpenedFile.editor.SelectedText
$text = $text -replace "<#(`n)?|(`n)?#>", ''
$Text = $text -replace "# >", "#>"
$Text = $text -replace "< #", "<#" $psise.CurrentOpenedFile.editor.InsertText("$text") } $psIse.CustomMenu.Submenus.Add("Comment Block", {ISE-BlockCommentOut}, "Ctrl+K") $psIse.CustomMenu.Submenus.Add("UnComment Block", {ISE-BlockCommentIn}, "Ctrl+SHift+K")

I'm not convinced that it is a good idea for such an extensions to use block comments symbols. Block comments do not nest neatly. They end with the end of the first included block comment and orphant closing block comment bracket become ordinary Comments.
You better never write anything behind a closing block comment in the first place.

Therefor included block comment symbols have to be escaped one way or other. Example
#> -> # > or #`>. Are there ways to establish conventions?

To be honest the other solution, to comment out every single line with its own #-symbol isn't trivial and besides some fiddeling with regular expressions, it involves temporary modification of the selection and I haven't it working yet.


CTP3 and PowerShell Community Extensions PSCX

I'm testing CTP 3 on Vista Ultimate in a Virtual Box.
Currently the only installed addon is PSCX 1.1.1.
To avoid some error messages I removed some of PSCX alias definitions,

for example all of the debug stuff.

I see no real clashes. Only there are 2 different commandlets Start-Process.

How to use a specific on of them
What are the differences between them

Does elevate based on Start-Process works with the CTP3 version as well.

Sonntag, 28. Dezember 2008

Yet another PowerShell Blog

This years december was a nice month.
We had Python 2.6, Python 3.0, IronPython 2.0 and at last even PowerShell V2 CTP 3.

So the situation in the different scripting languages is similar.

The basics advanced a big step and now can we wait for the essential addons to follow.

PowerShell Community Extensions seem to work smoothly - after disableing some duplicate aliases.
Powergui promises to support CTP3 soon, I 'll wait.

TFS, I can't yet say.

But in a few month we will happily convert our libraries to advanced functions and enjoy the uniform insource documentation.

And at least ISE, the undocumentend child. Let us explore, what we can do with it.