Archive for June 19th, 2009

Add your code snippets to PowerGUI

Want to add your PowerShell code snippets to PowerGUI Script Editor?

snippet_insert

It is actually as easy as adding your xml .snippet file to the C:\Program Files\PowerGUI\snippets folder.

You can create a new file manually or use any Visual Studio-compatible snippet editor. I am using Snipp Dogg which is a free open source project on codeplex. So my instructions below are using this tool but anything else would do.

1. Run the tool as Administrator (or it would not be able to save to Program Files if you are on Vista or later.)

2. You can see and study any of the snippet files shipped with PowerGUI:

PowerShell_Snippets

3. Click the New button to create a new snippet and then paste your code into the central pane – in my example I start with advanced function code from PowerShell v2 example:

new_snippet

4. If you want your snippet to have placeholders for certain variable names, parameters, and so on, you need to replace each of them with $some_kind_of_id$. In addition to that you can put $selected$ in front of the one you want to become selected once the snippet is inserted.

In my example, I am making the function name and the variable name these snippet parameters (in snippet lingo “literals”) and make the function name selected by default:

params

5. Fill out other snippet parameters in the right-hand pane (Snipp Dogg does not have powershell as a language option – shame on them – so either change it in the xml file later on or just leave it as csharp – PowerGUI does not check this field):

sniippet_description

6. Expand the Literals collection and click New to add a new literal (remember: we need to specify two):

snippet_new_literal

7. Fill out and save (by clicking OK) both functionname and param:

function_name_literal

snippet_param_paramname

8. Save the snippet to the C:\Program Files\PowerGUI\snippets folder (requires admin rights in Vista and later):

snippet_save

9. Start PowerGUI Script Editor and insert the snippet:

snippet_insert

snippet_inserted

That’s it! Happy scripting! 😉

Tags: , , ,

Advertisement

Legal

The posts on this blog are provided “as is” with no warranties and confer no rights. The opinions expressed on this site are mine and mine alone, and do not necessarily represent those of my employer - WSO2 or anyone else for that matter. All trademarks acknowledged.

© 2007-2014 Dmitry Sotnikov

June 2009
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

%d bloggers like this: