git.zsh 912 B

12345678910111213141516171819202122232425
  1. # Varables for themeing the git info prompt:
  2. # ZSH_THEME_GIT_PROMPT_PREFIX - Prefix at the very beginning of the prompt, before the branch name
  3. # ZSH_THEME_GIT_PROMPT_SUFFIX - At the very end of the prompt
  4. # ZSH_THEME_GIT_PROMPT_DIRTY - Text to display if the branch is dirty
  5. # ZSH_THEME_GIT_PROMPT_CLEAN - Text to display if the branch is clean
  6. ZSH_THEME_GIT_PROMPT_PREFIX="git:("
  7. ZSH_THEME_GIT_PROMPT_SUFFIX=")"
  8. ZSH_THEME_GIT_PROMPT_DIRTY="*"
  9. ZSH_THEME_GIT_PROMPT_CLEAN=""
  10. # get the name of the branch we are on
  11. function git_prompt_info() {
  12. ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  13. echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
  14. }
  15. parse_git_dirty () {
  16. if [[ $(git status | tail -n1) != "nothing to commit (working directory clean)" ]]; then
  17. echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
  18. else
  19. echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
  20. fi
  21. }