MenuItems/11-Add.ps1
<#
.Author Trevor Sullivan .Date 2014-06-17 .Description Adds a PowerShell ISE add-on menu item, which invokes a command to add the currently selected file to a Mercurial repository. #> $DisplayName = '_Add'; $KeyboardShorcut = 'Ctrl + Shift + A'; $Action = { $ArgumentList = 'add "{0}"' -f $psISE.CurrentFile.FullPath; $Process = Start-Process -FilePath hg.exe -ArgumentList $ArgumentList -PassThru -Wait -NoNewWindow; if ($Process.ExitCode -ne 0) { Write-Error -Message ('Error occurred while adding file: {0}' -f $Process.ExitCode); }; }; # Clean up old menu items, with the same name $HgMenu.Submenus.Where({ $PSItem.DisplayName -match $DisplayName }) | % { $HgMenu.Submenus.Remove($PSItem); }; # Add the new menu item $HgMenu.Submenus.Add($DisplayName, $Action, $KeyboardShorcut); |