Posh-git: Feature request: Show name of remote on prompt

Created on 3 Jul 2020  路  1Comment  路  Source: dahlbyk/posh-git

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.

Most helpful comment

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;
}

>All comments

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;
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

arafat-ar13 picture arafat-ar13  路  8Comments

ewgoforth picture ewgoforth  路  8Comments

GameOverture picture GameOverture  路  5Comments

Patabugen picture Patabugen  路  8Comments

jpierson picture jpierson  路  9Comments