PoshCode Logo PowerShell Code Repository

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

  1. function invoke-caretline
  2. {
  3. invoke-expression $([Regex]::Split($psISE.CurrentOpenedFile.Editor.text,"`r`n" )[$psISE.CurrentOpenedFile.Editor.caretline-1])
  4. }
  5. $psISE.CustomMenu.Submenus.Add("Run single line", {invoke-caretline} ,  'f7')
  6. function invoke-region([int] $num)
  7. {
  8. $ed = $psISE.CurrentOpenedFile.Editor
  9. $lines = [Regex]::Split($ed.text,"`r`n" )
  10. $foundfirst = -1
  11. $foundlast = -1
  12. for($count = 0;$count -le $lines.length-1;$count++)
  13.  {
  14.    if ($lines[$count].startswith("#region") -and $lines[$count].contains("@$num"))
  15.    { $foundfirst = $count;break}    
  16.  }
  17.  if($foundfirst -gt -1)
  18.  {
  19.  for ($count = $foundfirst; $count -le $lines.length-1;$count++)
  20.     {    
  21.     if ($lines[$count].startswith("#endregion") )
  22.    { $foundlast = $count;break}    
  23.     }
  24.    
  25.  if ($foundlast -gt -1)
  26.    {
  27.      $torun = ""
  28.      $lines[$foundfirst..$foundlast] | % { $torun+=$_ + "`r`n"}
  29.      invoke-expression $torun
  30.    }
  31.  }
  32.  
  33. }
  34.  $psISE.CustomMenu.Submenus.Add("run region 1", {invoke-region 1 },  'ctrl+1')
  35.  $psISE.CustomMenu.Submenus.Add("run region 2", {invoke-region 2 },  'ctrl+2')
  36.  $psISE.CustomMenu.Submenus.Add("run region 3", {invoke-region 3 },  'ctrl+3')
  37.  $psISE.CustomMenu.Submenus.Add("run region 4", {invoke-region 4 },  'ctrl+4')
  38.  $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.

Syntax highlighting:


Remember me