Last active
March 13, 2018 19:28
-
-
Save cameronove/df01db1613b05cbfa51dc3a1695e8e66 to your computer and use it in GitHub Desktop.
PowerShell prompt to emulate Git-Bash prompt.
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 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