Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. precmd() {
  2. local branch_ref branchless_ref
  3.  
  4. psvar=()
  5. branch_ref=$(git symbolic-ref -q HEAD 2>/dev/null)
  6. cleanliness=""
  7. if [[ ! -z $(git diff-index --name-only HEAD 2>/dev/null) ]]; then
  8. cleanliness="*"
  9. fi
  10. # We might be on a checked out branch:
  11. if [[ ! -z "$branch_ref" ]]; then
  12. psvar[1]=$cleanliness${branch_ref#refs/heads/}
  13. else
  14. branchless_ref=$(git name-rev --name-only HEAD 2>/dev/null)
  15. if [[ ! -z "$branchless_ref" ]]; then
  16. # Or we might happen to be on the same commit as (eg) master, but not have it checked out
  17. psvar[2]=$cleanliness${branchless_ref#(refs/heads/|remotes/)}$cleanliness
  18. fi
  19. fi
  20. }
  21.  
  22.  
  23. export PS1="[$PR_GREEN%n$PR_WHITE@$PR_GREEN%U%m%u$PR_NO_COLOR:$PR_RED%2c$PR_NO_COLOR]%(?.$.!) " # username, underlined host, 2 levels of current directory, '$' if last command succeeded, '!' otherwise.
  24.  
  25. # right-hand prompt:
  26. BRANCH_PROMPT="{$PR_LIGHT_GREEN%1v$PR_NO_COLOR}"
  27. HEADLESS_PROMPT="{$PR_LIGHT_RED%2v$PR_NO_COLOR}"
  28. # if psvar has 2 elements, we're not on a branch, but still have a suitable git name to use.
  29. # if psvar has 1 element, we're on a checked out branch (and obviously have a suitable git name to use)
  30. # otherwise, use a blank right-prompt.
  31. export RPS1="%(2v.$HEADLESS_PROMPT.%(1v.$BRANCH_PROMPT.))"
Add Comment
Please, Sign In to add comment