Created
May 19, 2018 14:21
-
-
Save shikaan/f96cb7a1ec7d1dfe12649a7f6aa10f81 to your computer and use it in GitHub Desktop.
Powershell script to make the prompt look like git-bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Write-BranchName () { | |
try { | |
$branch = git rev-parse --abbrev-ref HEAD | |
if ($branch -eq "HEAD") { | |
# we're probably in detached HEAD state, so print the SHA | |
$branch = git rev-parse --short HEAD | |
Write-Host " ($branch)" -ForegroundColor "red" | |
} | |
else { | |
# we're on an actual branch, so print it | |
Write-Host " ($branch)" -ForegroundColor "blue" | |
} | |
} catch { | |
# we'll end up here if we're in a newly initiated git repo | |
Write-Host " (no branches yet)" -ForegroundColor "yellow" | |
} | |
} | |
function prompt { | |
$meta = "$($env:UserName + "@" + $env:ComputerName) " | |
$path = "$($ExecutionContext.SessionState.Path.CurrentLocation -replace [RegEx]::Escape($home), "~")" | |
$userPrompt = "$('$' * ($nestedPromptLevel + 1)) " | |
Write-Host "`n" -NoNewline | |
if (Test-Path .git) { | |
Write-Host $meta -NoNewline -ForegroundColor "cyan" | |
Write-Host $path -NoNewline -ForegroundColor "green" | |
Write-BranchName | |
} | |
else { | |
Write-Host $meta -NoNewline -ForegroundColor "cyan" | |
# we're not in a repo so don't bother displaying branch name/sha | |
Write-Host $path -ForegroundColor "green" | |
} | |
return $userPrompt | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment