branch.plugin.zsh 683 B

1234567891011121314151617181920212223242526
  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. echo '☿' $(<"$current_dir/.hg/branch")
  20. return;
  21. fi
  22. # Defines path as parent directory and keeps looking for :)
  23. current_dir="${current_dir:h}"
  24. done
  25. }