2015-10-02 19:16:56 -07:00
|
|
|
# Branch: displays the current Git or Mercurial branch fast.
|
|
|
|
# Victor Torres <vpaivatorres@gmail.com>
|
|
|
|
# Oct 2, 2015
|
|
|
|
|
|
|
|
function branch_prompt_info() {
|
2021-12-01 09:49:42 -07:00
|
|
|
# Start checking in current working directory
|
|
|
|
local branch="" dir="$PWD"
|
|
|
|
while [[ "$dir" != '/' ]]; do
|
|
|
|
# Found .git directory
|
|
|
|
if [[ -d "${dir}/.git" ]]; then
|
|
|
|
branch="${"$(<"${dir}/.git/HEAD")"##*/}"
|
|
|
|
echo '±' "${branch:gs/%/%%}"
|
|
|
|
return
|
2015-10-02 19:16:56 -07:00
|
|
|
fi
|
2021-12-01 09:49:42 -07:00
|
|
|
|
|
|
|
# Found .hg directory
|
|
|
|
if [[ -d "${dir}/.hg" ]]; then
|
|
|
|
if [[ -f "${dir}/.hg/branch" ]]; then
|
|
|
|
branch="$(<"${dir}/.hg/branch")"
|
2016-05-29 02:25:17 -07:00
|
|
|
else
|
2021-12-01 09:49:42 -07:00
|
|
|
branch="default"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -f "${dir}/.hg/bookmarks.current" ]]; then
|
|
|
|
branch="${branch}/$(<"${dir}/.hg/bookmarks.current")"
|
2016-05-29 02:25:17 -07:00
|
|
|
fi
|
2021-12-01 09:49:42 -07:00
|
|
|
|
|
|
|
echo '☿' "${branch:gs/%/%%}"
|
|
|
|
return
|
2015-10-02 19:16:56 -07:00
|
|
|
fi
|
2021-12-01 09:49:42 -07:00
|
|
|
|
|
|
|
# Check parent directory
|
|
|
|
dir="${dir:h}"
|
2015-10-02 19:16:56 -07:00
|
|
|
done
|
|
|
|
}
|