Guest User

Untitled

a guest
May 24th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. function Write-BranchName () {
  2. try {
  3. $branch = git rev-parse --abbrev-ref HEAD
  4.  
  5. if ($branch -eq "HEAD") {
  6. # we're probably in detached HEAD state, so print the SHA
  7. $branch = git rev-parse --short HEAD
  8. Write-Host " ($branch)" -ForegroundColor "red"
  9. }
  10. else {
  11. # we're on an actual branch, so print it
  12. Write-Host " ($branch)" -ForegroundColor "blue"
  13. }
  14. } catch {
  15. # we'll end up here if we're in a newly initiated git repo
  16. Write-Host " (no branches yet)" -ForegroundColor "yellow"
  17. }
  18. }
  19.  
  20. function prompt {
  21. $meta = "$($env:UserName + "@" + $env:ComputerName) "
  22. $path = "$($ExecutionContext.SessionState.Path.CurrentLocation -replace [RegEx]::Escape($home), "~")"
  23. $userPrompt = "$('$' * ($nestedPromptLevel + 1)) "
  24.  
  25. Write-Host "`n" -NoNewline
  26.  
  27. if (Test-Path .git) {
  28. Write-Host $meta -NoNewline -ForegroundColor "cyan"
  29. Write-Host $path -NoNewline -ForegroundColor "green"
  30. Write-BranchName
  31. }
  32. else {
  33. Write-Host $meta -NoNewline -ForegroundColor "cyan"
  34. # we're not in a repo so don't bother displaying branch name/sha
  35. Write-Host $path -ForegroundColor "green"
  36. }
  37.  
  38. return $userPrompt
  39. }
Add Comment
Please, Sign In to add comment