my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.2 KiB

3 years ago
  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. local ret_status="%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})%?%{$reset_color%}"
  43. PROMPT=$'\n$(ssh_connection)%{$fg_bold[green]%}%n@%m%{$reset_color%}$(my_git_prompt) : %~\n[${ret_status}] %# '
  44. ZSH_THEME_PROMPT_RETURNCODE_PREFIX="%{$fg_bold[red]%}"
  45. ZSH_THEME_GIT_PROMPT_PREFIX=" $fg[white]‹ %{$fg_bold[yellow]%}"
  46. ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg_bold[magenta]%}↑"
  47. ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg_bold[green]%}↓"
  48. ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●"
  49. ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[red]%}●"
  50. ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[white]%}●"
  51. ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg_bold[red]%}✕"
  52. ZSH_THEME_GIT_PROMPT_SUFFIX=" $fg_bold[white]›%{$reset_color%}"