MenuItems/14-Remove.ps1

<#
    .Author
    Trevor Sullivan
 
    .Date
    2014-06-17
 
    .Description
    Adds a PowerShell ISE add-on menu item, which removes a file from
    a Mercurial repository.
#>

$DisplayName = '_Remove';
$KeyboardShorcut = 'Ctrl + Shift + V';

$Action = {
    $ArgumentList = 'remove "{0}"' -f $psISE.CurrentFile.FullPath;
    $Process = Start-Process -FilePath hg.exe -ArgumentList $ArgumentList -PassThru -Wait -NoNewWindow -RedirectStandardOutput;
    if ($Process.ExitCode -ne 0) {
        Write-Error -Message ('Error occurred removing file: {0}. Is the file part of the repository?' -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);