running regions in ISE (modification of post by view diff)
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/776"></script>download | new post
scripting for running regions by hotkeys in powershell v2 CTP3 ISE. http://www.karlprosser.com/coder
- function invoke-caretline
- {
- invoke-expression $([Regex]::Split($psISE.CurrentOpenedFile.Editor.text,"`r`n" )[$psISE.CurrentOpenedFile.Editor.caretline-1])
- }
- $psISE.CustomMenu.Submenus.Add("Run single line", {invoke-caretline} , 'f7')
- function invoke-region([int] $num)
- {
- $ed = $psISE.CurrentOpenedFile.Editor
- $lines = [Regex]::Split($ed.text,"`r`n" )
- $foundfirst = -1
- $foundlast = -1
- for($count = 0;$count -le $lines.length-1;$count++)
- {
- if ($lines[$count].startswith("#region") -and $lines[$count].contains("@$num"))
- { $foundfirst = $count;break}
- }
- if($foundfirst -gt -1)
- {
- for ($count = $foundfirst; $count -le $lines.length-1;$count++)
- {
- if ($lines[$count].startswith("#endregion") )
- { $foundlast = $count;break}
- }
- if ($foundlast -gt -1)
- {
- $torun = ""
- $lines[$foundfirst..$foundlast] | % { $torun+=$_ + "`r`n"}
- invoke-expression $torun
- }
- }
- }
- $psISE.CustomMenu.Submenus.Add("run region 1", {invoke-region 1 }, 'ctrl+1')
- $psISE.CustomMenu.Submenus.Add("run region 2", {invoke-region 2 }, 'ctrl+2')
- $psISE.CustomMenu.Submenus.Add("run region 3", {invoke-region 3 }, 'ctrl+3')
- $psISE.CustomMenu.Submenus.Add("run region 4", {invoke-region 4 }, 'ctrl+4')
- $psISE.CustomMenu.Submenus.Add("run region 5", {invoke-region 5 }, 'ctrl+5')
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository