git.zsh 1.0 KB

12345678910111213141516171819202122232425262728293031
  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. if [[ -d .git ]]; then
  13. ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  14. branch=${ref#refs/heads/}
  15. CURRENT_BRANCH="$ZSH_THEME_GIT_PROMPT_PREFIX${branch}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
  16. else
  17. CURRENT_BRANCH=''
  18. fi
  19. echo $CURRENT_BRANCH
  20. }
  21. parse_git_dirty () {
  22. if [[ $(git status | tail -n1) != "nothing to commit (working directory clean)" ]]; then
  23. echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
  24. else
  25. echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
  26. fi
  27. }