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