posh-git icon indicating copy to clipboard operation
posh-git copied to clipboard

Feature request: Show name of remote on prompt

Open cosmosb opened this issue 4 years ago • 2 comments

System Details

  • posh-git version/path: 0.7.3
  • PowerShell version: 5.1
  • Git version: git version 2.27.0.windows.1
  • Operating system name and version: Windows 10 x64 Version 2004 (Build 19041.330)

Issue Description

I read document on customizing prompt. I couldn't find option for this feature.

Another app, Cmder has feature where it shows name of the remote to which current branch is synced too. For exa.

image

posh-git shows this:

image

This is very handy when you have multiple remote destinations set up so you don't end up pushing to wrong destination. Right now you have to first run git status command to see where it is gonna push changes.

cosmosb avatar Jul 03 '20 17:07 cosmosb

I was able to get something close using the custom prompt function. The documentation for it is here in the Creating your own prompt function section. You'll need to hack it some more to get the colors the way you want, but it should be pretty easy to customize.

function prompt {
    $prompt = "$($ExecutionContext.SessionState.Path.CurrentLocation)";

    if ($Status = Get-GitStatus -Force) {
        $prompt += Write-Prompt -Object " [" -ForegroundColor Yellow;

        if (Write-GitBranchStatus -Status $Status) {
            $prompt += "$(Write-GitBranchStatus -Status $Status -NoLeadingSpace) ";
        }
        $prompt += "$(Write-GitBranchName -Status $Status -NoLeadingSpace) ";
        if ($Status.Upstream) {
            $prompt += "-> ";
            $prompt += Write-Prompt -Object "($($Status.Upstream)) | " -ForegroundColor Yellow;
        }
        if ($Status.HasIndex) {
            $prompt += "$(Write-GitIndexStatus -Status $Status -NoLeadingSpace) ";
        }
        if ($Status.HasWorking -and $Status.HasIndex) {
            $prompt += Write-Prompt -Object "| " -ForegroundColor Yellow;
        }
        if ($Status.HasWorking) {
            $prompt += "$(Write-GitWorkingDirStatus -Status $Status -NoLeadingSpace)$(Write-GitWorkingDirStatusSummary -Status $Status)";
        }

        $prompt += Write-Prompt -Object "]" -ForegroundColor Yellow;
    }
    $prompt += "> ";

    return $prompt;
}

csc027 avatar Aug 25 '20 05:08 csc027

How about this? Animation

I added a new property, ShowRemoteName having a default value of $false. The branch I switched to, 'add-name-of-remote' doesn't have an upstream value, hence 'origin/' isn't shown in the prompt.

And this screenshot shows a repo with 2 tracked repositories illustrating their names in the prompt: image

If anyone is curious, the animated gif was generated using ScreenToGif

@dahlbyk Thanks for this software! I've been using it happily for 5 years now.

marckassay avatar Jun 17 '22 15:06 marckassay