MenuItems/13-Status.ps1
<#
.Author Trevor Sullivan .Date 2014-06-17 .Description Adds a PowerShell ISE add-on menu item, which checks the status of a file in a Mercurial repository. #> $DisplayName = '_Status'; $KeyboardShorcut = 'Ctrl + Shift + S'; $Action = { $ArgumentList = 'status "{0}"' -f $psISE.CurrentFile.FullPath; $Process = Start-Process -FilePath hg.exe -ArgumentList $ArgumentList -PassThru -Wait -NoNewWindow -RedirectStandardOutput $env:Temp\Hg-Temp.txt; if ($Process.ExitCode -ne 0) { Write-Error -Message ('Error occurred retrieving file status: {0}. Do you have a Mercurial repository? Is the file beneath the repository folder?' -f $Process.ExitCode); } else { Get-Content -Path $env:Temp\Hg-Temp.txt; } }; # 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); |