Skip to content

Instantly share code, notes, and snippets.

@cameronove
Last active March 13, 2018 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronove/df01db1613b05cbfa51dc3a1695e8e66 to your computer and use it in GitHub Desktop.
Save cameronove/df01db1613b05cbfa51dc3a1695e8e66 to your computer and use it in GitHub Desktop.
PowerShell prompt to emulate Git-Bash prompt.
function prompt {
$NearestGitRepo = $null
$Folder = $pwd.Path
do{
if(Test-Path $Folder\.git){
$NearestGitRepo = $Folder
}
$Folder = Split-Path $Folder
}until($NearestGitRepo -or $Folder -eq '')
if ($NearestGitRepo) {
$GitUser = "$env:USERNAME@$env:COMPUTERNAME "
$GitConsole = "PS_$([regex]::Matches($host.Name,'[A-Z]').value -join '') "
$GitPath = "/$Pwd " -replace ':' -replace '\\', '/'
$GitBranch = "($((get-content "$NearestGitRepo\.git\head").split('/')[-1]))"
Write-Host $GitUser -ForegroundColor Green -NoNewline
Write-Host $GitConsole -ForegroundColor Magenta -NoNewline
Write-Host $GitPath -ForegroundColor Yellow -NoNewline
Write-Host $GitBranch -ForegroundColor Cyan
'$ '
}
else {
$host.UI.RawUI.WindowTitle = "TAB '$($psise.CurrentPowerShellTab.DisplayName)' Location --> $(Get-Location)"
$splitpath = $pwd.path.Split('\')
if ($splitpath.count -le 2) {
"PS $pwd>"
}
else {
"PS $($pwd.path.split('\')[0])\...\$($pwd.path.split('\')[-1])>"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment