branch.plugin.zsh 859 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Branch: displays the current Git or Mercurial branch fast.
  2. # Victor Torres <vpaivatorres@gmail.com>
  3. # Oct 2, 2015
  4. function branch_prompt_info() {
  5. # Start checking in current working directory
  6. local branch="" dir="$PWD"
  7. while [[ "$dir" != '/' ]]; do
  8. # Found .git directory
  9. if [[ -d "${dir}/.git" ]]; then
  10. branch="${"$(<"${dir}/.git/HEAD")"##*/}"
  11. echo '±' "${branch:gs/%/%%}"
  12. return
  13. fi
  14. # Found .hg directory
  15. if [[ -d "${dir}/.hg" ]]; then
  16. if [[ -f "${dir}/.hg/branch" ]]; then
  17. branch="$(<"${dir}/.hg/branch")"
  18. else
  19. branch="default"
  20. fi
  21. if [[ -f "${dir}/.hg/bookmarks.current" ]]; then
  22. branch="${branch}/$(<"${dir}/.hg/bookmarks.current")"
  23. fi
  24. echo '☿' "${branch:gs/%/%%}"
  25. return
  26. fi
  27. # Check parent directory
  28. dir="${dir:h}"
  29. done
  30. }