2015-10-03 10:16:56 +08:00
|
|
|
# Branch: displays the current Git or Mercurial branch fast.
|
|
|
|
# Victor Torres <vpaivatorres@gmail.com>
|
|
|
|
# Oct 2, 2015
|
|
|
|
|
|
|
|
function branch_prompt_info() {
|
2021-12-02 00:49:42 +08: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-03 10:16:56 +08:00
|
|
|
fi
|
2021-12-02 00:49:42 +08:00
|
|
|
|
|
|
|
# Found .hg directory
|
|
|
|
if [[ -d "${dir}/.hg" ]]; then
|
|
|
|
if [[ -f "${dir}/.hg/branch" ]]; then
|
|
|
|
branch="$(<"${dir}/.hg/branch")"
|
2016-05-29 17:25:17 +08:00
|
|
|
else
|
2021-12-02 00:49:42 +08:00
|
|
|
branch="default"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -f "${dir}/.hg/bookmarks.current" ]]; then
|
|
|
|
branch="${branch}/$(<"${dir}/.hg/bookmarks.current")"
|
2016-05-29 17:25:17 +08:00
|
|
|
fi
|
2021-12-02 00:49:42 +08:00
|
|
|
|
|
|
|
echo '☿' "${branch:gs/%/%%}"
|
|
|
|
return
|
2015-10-03 10:16:56 +08:00
|
|
|
fi
|
2021-12-02 00:49:42 +08:00
|
|
|
|
|
|
|
# Check parent directory
|
|
|
|
dir="${dir:h}"
|
2015-10-03 10:16:56 +08:00
|
|
|
done
|
|
|
|
}
|