git.zsh 594 B

12345678910111213141516171819202122
  1. # get the name of the branch we are on
  2. function git_prompt_info() {
  3. ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  4. echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
  5. }
  6. parse_git_dirty () {
  7. if [[ -n $(git status -s 2> /dev/null) ]]; then
  8. echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
  9. else
  10. echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
  11. fi
  12. }
  13. #
  14. # Will return the current branch name
  15. # Usage example: git pull origin $(current_branch)
  16. #
  17. function current_branch() {
  18. ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  19. echo ${ref#refs/heads/}
  20. }