mortalscumbag.zsh-theme 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. function my_git_prompt() {
  2. tester=$(git rev-parse --git-dir 2> /dev/null) || return
  3. INDEX=$(git status --porcelain 2> /dev/null)
  4. STATUS=""
  5. # is branch ahead?
  6. if $(echo "$(git log origin/$(git_current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
  7. STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_AHEAD"
  8. fi
  9. # is branch behind?
  10. if $(echo "$(git log HEAD..origin/$(git_current_branch) 2> /dev/null)" | grep '^commit' &> /dev/null); then
  11. STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_BEHIND"
  12. fi
  13. # is anything staged?
  14. if $(echo "$INDEX" | command grep -E -e '^(D[ M]|[MARC][ MD]) ' &> /dev/null); then
  15. STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_STAGED"
  16. fi
  17. # is anything unstaged?
  18. if $(echo "$INDEX" | command grep -E -e '^[ MARC][MD] ' &> /dev/null); then
  19. STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED"
  20. fi
  21. # is anything untracked?
  22. if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
  23. STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED"
  24. fi
  25. # is anything unmerged?
  26. if $(echo "$INDEX" | command grep -E -e '^(A[AU]|D[DU]|U[ADU]) ' &> /dev/null); then
  27. STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED"
  28. fi
  29. if [[ -n $STATUS ]]; then
  30. STATUS=" $STATUS"
  31. fi
  32. echo "$ZSH_THEME_GIT_PROMPT_PREFIX$(my_current_branch)$STATUS$ZSH_THEME_GIT_PROMPT_SUFFIX"
  33. }
  34. function my_current_branch() {
  35. echo $(git_current_branch || echo "(no branch)")
  36. }
  37. function ssh_connection() {
  38. if [[ -n $SSH_CONNECTION ]]; then
  39. echo "%{$fg_bold[red]%}(ssh) "
  40. fi
  41. }
  42. function _toolbox_prompt_info() {
  43. if typeset -f toolbox_prompt_info > /dev/null; then
  44. toolbox_prompt_info
  45. fi
  46. }
  47. local ret_status="%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})%?%{$reset_color%}"
  48. PROMPT=$'\n$(_toolbox_prompt_info)$(ssh_connection)%{$fg_bold[green]%}%n@%m%{$reset_color%}$(my_git_prompt) : %~\n[${ret_status}] %# '
  49. ZSH_THEME_PROMPT_RETURNCODE_PREFIX="%{$fg_bold[red]%}"
  50. ZSH_THEME_GIT_PROMPT_PREFIX=" $fg[white]‹ %{$fg_bold[yellow]%}"
  51. ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg_bold[magenta]%}↑"
  52. ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg_bold[green]%}↓"
  53. ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●"
  54. ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[red]%}●"
  55. ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[white]%}●"
  56. ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg_bold[red]%}✕"
  57. ZSH_THEME_GIT_PROMPT_SUFFIX=" $fg_bold[white]›%{$reset_color%}"