0
function prompt {
    $time = Get-Date -Format "HH:mm"
    $location = (Get-Location -PSProvider FileSystem).Path

    $promptText = "["
    $promptText += "$([char]27)[96m$time$([char]27)[0m "
    $promptText += "$([char]27)[32momkrbhagat$([char]27)[0m "
    $promptText += "$([char]27)[35m$location$([char]27)[0m"

    Write-Host $promptText -NoNewline
    return " ~ "
}

This is my own custom prompt for PowerShell. I have posh-git installed and imported module in my $PROFILE too. Git commands tab completion also works well, but when I initialize my git repository didn't see Git status prompt. I think my own custom prompt affects showing Git status prompt. So, how can I integrate my own prompt and Git status prompt.

I expect the following output : [HH:mm] omkrbhagat C:\Users\onkar (master) ~

For this I append the following line : if (Test-Path variable:GitPromptSettings) { Write-VcsStatus }

But still didn't work. Apart from that when I initialize the git repository only then and then the git status prompt should be shown.

  • 1
    If you're replacing the default `prompt` then I think you need to call `& $GitPromptScriptBlock` at the end (see https://github.com/dahlbyk/posh-git#gitpromptscriptblock) – Thomas Glaser Jul 10 '23 at 10:49
  • @Thomas Glaser Can you show how can I exactly achieve that. Additionally I want to see posh-git Git status prompt only when I initialize repository. This can be achieve using `if-else` but I don't know exactly how. – Omkar Bhagat Jul 11 '23 at 20:13

0 Answers0