branch.plugin.zsh 787 Bytes
Newer Older
Victor Torres's avatar
Victor Torres committed
1
2
3
4
5
6
# Branch: displays the current Git or Mercurial branch fast.
# Victor Torres <vpaivatorres@gmail.com>
# Oct 2, 2015

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