Posts mit dem Label CTP3 werden angezeigt. Alle Posts anzeigen
Posts mit dem Label CTP3 werden angezeigt. Alle Posts anzeigen

Donnerstag, 15. Januar 2009

ISE and Read-Host why not read from Commandpane.Editor

I really hope, that in the final PowerShell V2 there is a way to use Read-Host reading from Commandpane.Editor without any Prompt-Dialog.



Without this many interessting Custum Menue Extensions like this one
are slowed down by some additional GUI-Elements.



I do not want to isolate the prompt input from the command history.



I want to be able to clone ISQL/w or SQL Querry Analyzer or 1000 other 'inconceivable' things within ISE.



I want some jobs be done while xx-Studio still is loading.


This refers To Visual-Studio as well as Toad or Power-GUI or SQL-Management Studio.



Dont't panic.



Bernd


Mittwoch, 14. Januar 2009

Hint to test ISE-Extensions

I have some difficulties using regular expressions on the CRLF sequences within editor.Text

Using format-hex from Hex Dumper in Monad. I just need to select some text and can see that lines within the editors are CRLF delimited too

[char[]]$psise.CurrentOpenedFile.editor.SelectedText | format-hex


Mittwoch, 7. Januar 2009

ISE - Snippets Variant 2

Hello again

poetter postet some ISE Custom menue extensions at poshcode.

He displays a list and uses a prompt dialog to select the choice.

Well the list might get quite long and I tried a different approach: selecting the choice by either the selected text or by the text left to the cursor. Here the result, which is based on his code.


#requires -version 2.0
#
# ISE-Snippets module v 1.0
#
# DEVELOPED FOR CTP3
#
# See comments for each function for changes ...
#
#############################################################################################################
#
# As a shortcut for every snippet would be to much, I created Add-Snippet which presents a menu.
#
# Feel free to add your own snippets to function Add-Snippet but please contribute your changes here
#
#############################################################################################################
#
# Provides Code Snippets for working with ISE
#
# Add-Snippet - Presents menu for snippet selection
#
# Add-SnippetToEditor - Adds a snippet at caret position
#
#############################################################################################################


## Add-Snippet
#
#############################################################################################################
#
# Presents menu for snippet selection
#
#############################################################################################################
function Add-Snippet
{
$snippets = @{
"region" = @( "#region", "#endregion" )
"function" = @( "function FUNCTION_NAME", "{", "}" )
"param" = @( "param ``", "(", ")" )
"if" = @( "if ( CONDITION )", "{", "}" )
"else" = @( "else", "{", "}" )
"elseif" = @( "elseif ( CONDITION )", "{", "}" )
"foreach" = @( "foreach ( ITEM in COLLECTION )", "{", "}" )
"for" = @( "foreach ( INIT; CONDITION; REPEAT )", "{", "}" )
"while" = @( "while ( CONDITION )", "{", "}" )
"dowhile" = @( "do" , "{", "}", "while ( CONDITION )" )
"dountil" = @( "do" , "{", "}", "until ( CONDITION )" )
"try" = @( "try", "{", "}" )
"catch" = @( "catch", "{", "}" )
"catch [<error type>] " = @( "catch [ERROR_TYPE]", "{", "}" )
"finaly" = @( "finaly", "{", "}" )
}


$editor = $psISE.CurrentOpenedFile.Editor
if ( $editor.SelectedText.length -eq 0) {
$caretLine = $editor.CaretLine
$caretColumn = $editor.CaretColumn
$text = $editor.Text.Split(
"`n")
$line = $text[$caretLine -1]
$LeftOfCarret = $line.substring(0, $caretColumn - 1)
$parts = $LeftOfCarret.split(
"")
$len = $parts[-1].length
$start = $caretColumn - $len
$editor.select($caretLine, $start, $caretLine, $caretColumn )
}

$snippetName = $editor.SelectedText
$editor.insertText('')
Add-SnippetToEditor $snippets[$snippetName]
}

## Add-SnippetToEditor
##############################################################################################################
## Adds a snippet at caret position
##############################################################################################################
function Add-SnippetToEditor
{
param `
(
[string[]] $snippet
)

$editor = $psISE.CurrentOpenedFile.Editor
$caretLine = $editor.CaretLine
$caretColumn = $editor.CaretColumn
$text = $editor.Text.Split(
"`n")
$newText = @()
if ( $caretLine -gt 1 )
{
$newText += $text[0..($caretLine -2)]
}
$curLine = $text[$caretLine -1]
$indent = $curline -replace
"[^\t ]", ""
foreach ( $snipLine in $snippet )
{
$newText += $indent + $snipLine
}
if ( $caretLine -ne $text.Count )
{
$newText += $text[$caretLine..($text.Count -1)]
}
$editor.Text = [String]::Join(
"`n", $newText)
$editor.SetCaretPosition($caretLine, $caretColumn)
}

#Export-ModuleMember Add-Snippet


##############################################################################################################
## Inserts command Add Snippet to custom menu
##############################################################################################################
if (-not( $psISE.CustomMenu.Submenus | where { $_.DisplayName -eq
"_Snippet" } ) )
{
$null = $psISE.CustomMenu.Submenus.Add(
"_Snippet", {Add-Snippet}, "Ctrl+Alt+S")
}


Thanks and congratulation to Dmitry for delivering the new CTP 3 compatible Powergui version and telling in his blog about export html. I just tried this here for the code above.

The above code is ready for every days use. It is just a design study in programming the selection. Personally I don't use snippets in any editor while coding, just a question of personal taste.

In the long term I will use this to interactivly transform T-SQL into PL/SQL. I guess in the end, this will save a lot of my time.

Thanks to the PowerShell Team who did such a good and extendable job. A real christmas present.

Enjoy extending

Bernd

$psIse.CustomMenu - undocumented features

Hello again.

Having CustomMenu, but no Remove() ?
Using my fingers instead of my brain I tried command completions on $psIse.CustomMenu.Submenus.R - Tab and there it was.

After a little break I just did

$psIse.CustomMenu.Submenus.PSBase | gm



Finaly I had:

$psIse.CustomMenu.Submenus.Add("_Dir", {dir}, "Ctrl+M")
$psIse.CustomMenu.Submenus[$psIse.CustomMenu.Submenus.count-1].DisplayName
$psIse.CustomMenu.Submenus.remove($psIse.CustomMenu.Submenus[$psIse.CustomMenu.Submenus.count-1])
$psIse.CustomMenu.Submenus.RemoveAt($psIse.CustomMenu.Submenus.count-1)
# Yet I have no sane example how to use the next one
#$psIse.CustomMenu.Submenus.Insert($pos, $psMenuItem)

My Wishlist for further ISE Extensions
  • Custum context-menues
  • A way to determin which pane has the focus, the inverse to Focus() of Editor Objects
  • folding
  • custum syntax coloring
  • a way a read the input from the command pane, enabeling to write ones owns read execute display loops
  • and some hooks, i.e. events pane switch or whatever it might be called, saveas , open etc.

Enjoy discovering


Bernd

Montag, 5. Januar 2009

New ideas to (mis-?) use ISE

I asked Jeffrey Snover whether ISE is Powershell specific. His answer is very encouraging, but goes not as far as to use it for SQL-scripts.



One of my office duties is manually converting stored procedures form SQL-Server to ORACLE.



Yesterday poetter posted ISE-Snippets. The way to use a prompt dialog to select a choice doesn't please me. I would rather select depending on a selection or the characters to the left of the carret. Isn't that rather similar to the task of tab-completion ?



I find, the best way would be typ some beginning and using some hot-key cycle through the possible snippets.



During the night emerged the idea of using this technic to convert SQL-snippets from SQL-Server to Oracle.

Just tried to load one of my sql-scripts into ISE. Loading ok, no syntax-coloring, that's ok.



I believe todays ISE (CTP3) has the aptitude to fullfil this task.

Concerning the performance, I expect the final V2 release to be powerfull enough.

PowerGUI 1.6.0 Now Available

Yesterday late night I noticed the new version. Immedeatly downloaded and started.
I have still a little problem with the profile execution, but it makes a good impression.
Now hint on the download side, the it is the new version for Powershell V2 CTP3.
but it seems to be.



Congratulation to the PowerGui team good job.



Bernd

Donnerstag, 1. Januar 2009

No risk no fun - I updated my Vista host to VP 2 CTP 3

Just upgraded my Vista Ultimate Notebook from CTP 2 to CTP 3.

Having a german version there seams to be no way to instatall WinRM 2.0 CTP 3.

Adaption of PSCX required some outcommenting of aliases, and seams working.

Next time I install a new Vista virtual machine, I' chose an englisch system.

Meanwhile I found out, what to do to get get at the helpfiles:

Being elevated


1)
copy-item $pshome\en-us\*.help.txt $pshome\de-DE


2)
Copy-Item $env:windir\help\mui\0409\WindowsPowerShellHelp.chm $env:windir\help\mui\0407



Currently I' fiddling around with the prompt function. For ISE I need a different version, different colors etc. and further I'm selection usefull stuff for the custom menue.

And finally in Microsoft Connect I proposed ID 390290 that ISE will ask the user when the currently edited file is changed externally. If you agree, please vote for it.



Happy scripting


Bernd

Montag, 29. Dezember 2008

ISE - BlockComment BlockUncomment custom menue

Hello everyone,

based on ideas from Andy Schneider http://get-powershell.com/2008/12/29/ise-comment-out-a-block-of-text/ 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# "
$psise.CurrentOpenedFile.editor.InsertText($text)
}


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.


Bernd

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.



Bernd