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 " ~ "
}
6
  • Hello, what is the specific question here? You know what var to add to the prompt, you got the prompt function. Is something not working or do you not know how to append the variable? Commented Jul 11, 2023 at 11:17
  • @Destroy666 it does work in GIT. Commented Jul 11, 2023 at 11:34
  • @RohitGupta I have no idea what you mean and how that answers my comments. Commented Jul 11, 2023 at 11:59
  • @Destroy666 I mean that when I initialize the git repository, only then I want to see the posh-git Git status prompt. It can be achieve using if-else but I don't know how exactly I can do that. Commented Jul 11, 2023 at 20:06
  • What does it show in non-repository directories? Commented Jul 11, 2023 at 20:19

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.