MenuItems/12-Commit.ps1

<#
    .Author
    Trevor Sullivan
 
    .Date
    2014-06-17
 
    .Description
    Adds a PowerShell ISE add-on menu item, which invokes a
    command to commit file changes to a Mercurial repository.
#>

$DisplayName = '_Commit';
$KeyboardShorcut = 'Ctrl + Shift + C';

$Action = {
    $CommitMessage = [SullivanSoft.Prompt]::ShowDialog('Please enter a commit message', 'Mercurial');

    $ArgumentList = 'commit --message "{0}" "{1}"' -f $CommitMessage, $psISE.CurrentFile.FullPath;
    #Write-Host -ForegroundColor Green -Object $ArgumentList;
    $Process = Start-Process -FilePath hg.exe -ArgumentList $ArgumentList -PassThru -Wait -NoNewWindow;
    if ($Process.ExitCode -ne 0) {
        Write-Error -Message ('Error occurred while committing changes: {0}. Have you added the file to 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);