3

I made my own custom prompt for PowerShell and my prompt be look like : [HH:mm] omkrbhagat C:\Users\onkar ~

Then, I installed posh-git module and import in my profile. Auto tab completion for git commands are working well but I can't see git status prompt. Then I came to know that if I have my own custom prompt then git status prompt can't consolidate with custom prompt. For this I need to use & $GitPromptScriptBlock. Can you show me how to achieve that and along with that I want git status prompt only when I initialize the git repository.

This is my own custom prompt for pwsh :

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"

$promptText += " $(Write-VcsStatus -NoColor) "  # Add Git status prompt

Write-Host $promptText -NoNewline
return " ~ "

}

0 Answers0