Dienstag, 20. Januar 2009

Schmierzettel 1 [my scratch pad 1]

These notes may give you an impression, of what to expect in this blog in the future.

resolution(s) [Vorsätze 2009]

Improve testing before posting of scripts [ Test 3 times ]

------------
currently exploring:
  • tab expansion to blank it seems rather unpredictable
  • CR/LF regular expressions line splitting -- I observed funny things
  • Format-Hex basic test function for the above


=== propsals for ISE I'm preparing ====

menues:
save as - rename file -- both are needed
delete file (and tab -- after prompting)
print
Options
recently opened files

custumizable contex menue

performance: expanding selected-text using mouse is too slow

Read-host from command panael

publish events:
file opened
file closed

==============================
waiting for:
ISE-CREAME
PSCX CTP3 version
Virtual Box Windows 7 shared folder

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


PSCX Format-HEX not working

I hope PowerShell Community Extension adapt to PowerShell V2 CTP3 soon.


Currently I can't use Format-Hex and as Start-Process is part of CTP3 it should be removed.


I'm not testing in any systematic way, just stumbling into it, when I will try something.

If ISE could print, it could replace Notepad it behaves well with moderaztrate sized files. Only extending selections using the mouse is sometimes boaringly slow.

And when I have a number of files loaded, switching tabs fails. After closing one, I can continue my work.

No data lost till now.

Ein großes Dankeschön an das Powershell Team.

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


Freitag, 9. Januar 2009

advises to change Bloglayout are wellcome

I need more width.

Thanks in advance.

Sorting lines in ISE

You can sort lines in ISE based on selected columns.



Yesterday I read about #requires.

Just wondering why there is no # requires -module

Donnerstag, 8. Januar 2009

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

I started using twitter

Yesterday I started using twitter. Some days earlier looking for infos about CTP3 I stumbled at Tweed Grid and got a lot of useful links from there. If you are curious there I use the name bernd_k.

Meanwhile I have a nice collection of functions for ISE Custommenue, but not yet the means to present them in a pretty way in this blog.

On of my favorites is Expand-Alias.

I heard from Karl Prosser that he plans a codeplex project called #powershell ISE-Cream, to make module of ISE extentions and improvements.

I believe I will prefer that. Dumping ones scripts at PoshCode returns little feedback.

By the way, any advice for better presentation of Powershell script within my blog are welcome. Best it would be some PS-script.

Working in Bavaria tomorrow is another free day (sounds like direct translated german, I'm not going to look it up - perhaps one day there is a Powershell version of NLTK
, yet it is only python 2.4) and wednesday back to job.

Just found Add-Snippet I'll try to convert it to something that is based on selected text or so.

And tomorrow I spent some hours in the ICE returning to Munich. Good time to read the CTP3 helpfile.

Enjoy the snow and PowerShell

Bernd

Samstag, 3. Januar 2009

[CTP3] ISE and drag and drop

Hello everone,

do you no, that you can not only load files in ISE by drag and drop from an explorer window, but also from its own fileselection dialog.
Very cool.

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