branch.plugin.zsh 663 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. path=$(pwd)
  7. # While current path is not root path
  8. while [ $path != '/' ];
  9. do
  10. # Git repository
  11. if [ -d ${path}/.git ];
  12. then
  13. echo '±' $(/bin/cat ${path}/.git/HEAD | /usr/bin/cut -d / -f 3-)
  14. return;
  15. fi
  16. # Mercurial repository
  17. if [ -d ${path}/.hg ];
  18. then
  19. echo '☿' $(/bin/cat ${path}/.hg/branch)
  20. return;
  21. fi
  22. # Defines path as parent directory and keeps looking for :)
  23. path=$(/usr/bin/dirname $path)
  24. done
  25. }