branch.plugin.zsh 787 B

12345678910111213141516171819202122232425262728293031
  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. # Defines path as current directory
  6. local current_dir=$PWD
  7. # While current path is not root path
  8. while [[ $current_dir != '/' ]]
  9. do
  10. # Git repository
  11. if [[ -d "${current_dir}/.git" ]]
  12. then
  13. echo '±' ${"$(<"$current_dir/.git/HEAD")"##*/}
  14. return;
  15. fi
  16. # Mercurial repository
  17. if [[ -d "${current_dir}/.hg" ]]
  18. then
  19. if [[ -f "$current_dir/.hg/branch" ]]
  20. then
  21. echo '☿' $(<"$current_dir/.hg/branch")
  22. else
  23. echo '☿ default'
  24. fi
  25. return;
  26. fi
  27. # Defines path as parent directory and keeps looking for :)
  28. current_dir="${current_dir:h}"
  29. done
  30. }