diff --git a/posh-hg/HgPrompt.ps1 b/posh-hg/HgPrompt.ps1 new file mode 100644 index 000000000..105958601 --- /dev/null +++ b/posh-hg/HgPrompt.ps1 @@ -0,0 +1,111 @@ +# For backwards compatibility +$global:HgPromptSettings = $global:PoshHgSettings + +function Write-HgStatus($status = (get-hgStatus $global:PoshHgSettings.GetFileStatus $global:PoshHgSettings.GetBookmarkStatus)) { + if ($status) { + $s = $global:PoshHgSettings + $sb = [System.Text.StringBuilder]::new() + + $branchFg = $s.BranchForegroundColor + $branchBg = $s.BranchBackgroundColor + + if($status.Behind) { + $branchFg = $s.Branch2ForegroundColor + $branchBg = $s.Branch2BackgroundColor + } + + if ($status.MultipleHeads) { + $branchFg = $s.Branch3ForegroundColor + $branchBg = $s.Branch3BackgroundColor + } + + $sb | Write-Prompt $s.BeforeText -BackgroundColor $s.BeforeBackgroundColor -ForegroundColor $s.BeforeForegroundColor + $sb | Write-Prompt $status.Branch -BackgroundColor $branchBg -ForegroundColor $branchFg + + if($status.Added) { + $sb | Write-Prompt "$($s.AddedStatusPrefix)$($status.Added)" -BackgroundColor $s.AddedBackgroundColor -ForegroundColor $s.AddedForegroundColor + } + if($status.Modified) { + $sb | Write-Prompt "$($s.ModifiedStatusPrefix)$($status.Modified)" -BackgroundColor $s.ModifiedBackgroundColor -ForegroundColor $s.ModifiedForegroundColor + } + if($status.Deleted) { + $sb | Write-Prompt "$($s.DeletedStatusPrefix)$($status.Deleted)" -BackgroundColor $s.DeletedBackgroundColor -ForegroundColor $s.DeletedForegroundColor + } + + if ($status.Untracked) { + $sb | Write-Prompt "$($s.UntrackedStatusPrefix)$($status.Untracked)" -BackgroundColor $s.UntrackedBackgroundColor -ForegroundColor $s.UntrackedForegroundColor + } + + if($status.Missing) { + $sb | Write-Prompt "$($s.MissingStatusPrefix)$($status.Missing)" -BackgroundColor $s.MissingBackgroundColor -ForegroundColor $s.MissingForegroundColor + } + + if($status.Renamed) { + $sb | Write-Prompt "$($s.RenamedStatusPrefix)$($status.Renamed)" -BackgroundColor $s.RenamedBackgroundColor -ForegroundColor $s.RenamedForegroundColor + } + + if($s.ShowTags -and ($status.Tags.Length -or $status.ActiveBookmark.Length)) { + $sb | Write-Prompt $s.BeforeTagText -NoNewLine + + if($status.ActiveBookmark.Length) { + $sb | Write-Prompt $status.ActiveBookmark -ForegroundColor $s.BranchForegroundColor -BackgroundColor $s.TagBackgroundColor + if($status.Tags.Length) { + $sb | Write-Prompt " " -ForegroundColor $s.TagSeparatorColor -BackgroundColor $s.TagBackgroundColor + } + } + + $tagCounter=0 + $status.Tags | % { + $color = $s.TagForegroundColor + + $sb | Write-Prompt $_ -ForegroundColor $color -BackgroundColor $s.TagBackgroundColor + + if($tagCounter -lt ($status.Tags.Length -1)) { + $sb | Write-Prompt ", " -ForegroundColor $s.TagSeparatorColor -BackgroundColor $s.TagBackgroundColor + } + $tagCounter++; + } + } + + if($s.ShowPatches) { + $patches = Get-MqPatches + if($patches.All.Length) { + $sb | Write-Prompt $s.BeforePatchText -NoNewLine + + $patchCounter = 0 + + $patches.Applied | % { + $sb | Write-Prompt $_ -ForegroundColor $s.AppliedPatchForegroundColor -BackgroundColor $s.AppliedPatchBackgroundColor + if($patchCounter -lt ($patches.All.Length -1)) { + $sb | Write-Prompt $s.PatchSeparator -ForegroundColor $s.PatchSeparatorColor + } + $patchCounter++; + } + + $patches.Unapplied | % { + $sb | Write-Prompt $_ -ForegroundColor $s.UnappliedPatchForegroundColor -BackgroundColor $s.UnappliedPatchBackgroundColor + if($patchCounter -lt ($patches.All.Length -1)) { + $sb | Write-Prompt $s.PatchSeparator -ForegroundColor $s.PatchSeparatorColor + } + $patchCounter++; + } + } + } + + if($s.ShowRevision -and $status.Revision) { + $sb | Write-Prompt " <" -BackgroundColor $s.TagBackgroundColor -ForegroundColor $s.TagForegroundColor + $sb | Write-Prompt $status.Revision -BackgroundColor $s.TagBackgroundColor -ForegroundColor $s.TagForegroundColor + $sb | Write-Prompt ">" -BackgroundColor $s.TagBackgroundColor -ForegroundColor $s.TagForegroundColor + } + + + $sb | Write-Prompt $s.AfterText -BackgroundColor $s.AfterBackgroundColor -ForegroundColor $s.AfterForegroundColor + + $sb.ToString() + } +} + +# Add scriptblock that will execute for Write-VcsStatus +$Global:VcsPromptStatuses += { + Write-HgStatus +} diff --git a/posh-hg/HgTabExpansion.ps1 b/posh-hg/HgTabExpansion.ps1 new file mode 100644 index 000000000..18f91952d --- /dev/null +++ b/posh-hg/HgTabExpansion.ps1 @@ -0,0 +1,331 @@ +$script:hgCommands = @() +$script:hgflowStreams = @() + +function HgTabExpansion($lastBlock) { + switch -regex ($lastBlock) { + + #handles hgtk help + #handles hgtk + 'thg (help )?(\S*)$' { + thgCommands($matches[2]); + } + + #handles hg update + #handles hg merge + 'hg (up|update|merge|co|checkout) (\S*)$' { + findBranchOrBookmarkOrTags($matches[2]) + } + + #Handles hg pull -B + 'hg pull (-\S* )*-(B) (\S*)$' { + hgRemoteBookmarks($matches[3]) + hgLocalBookmarks($matches[3]) + } + + #Handles hg push -B + 'hg push (-\S* )*-(B) (\S*)$' { + hgLocalBookmarks($matches[3]) + } + + #Handles hg bookmark + 'hg (book|bookmark) (\S*)$' { + hgLocalBookmarks($matches[2]) + } + + #Handles hg push + #Handles hg pull + #Handles hg outgoing + #Handles hg incoming + 'hg (push|pull|outgoing|incoming) (-\S* )*(\S*)$' { + hgRemotes($matches[3]) + } + + #handles hg help + #handles hg + 'hg (help )?(\S*)$' { + hgCommands($matches[2]); + } + + #handles hg --