Show branch id if not on tip

If not on the tip it's often useful to know where we are exactly. This
commit brings this feature. If on the tip, then just the branch name is
displayed, but if not, then it's displayed like that: `branchname@id`.
This commit is contained in:
Romain Failliot 2018-02-18 19:15:36 -05:00
parent d5f3c198c9
commit e3977e439c

View File

@ -38,13 +38,23 @@ function in_hg() {
fi fi
} }
function hg_get_branch_id() {
local hg_id_tip=`hg log -T "{node|short}" -l 1 -b .`
local hg_id=`hg id -i -r .`
if [[ $hg_id != $hg_id_tip ]]; then
echo "@${hg_id}"
fi
}
function hg_get_branch_name() { function hg_get_branch_name() {
local hg_dir=$(hg_get_dir) local hg_dir=$(hg_get_dir)
if [[ $hg_dir != "" ]]; then if [[ $hg_dir != "" ]]; then
local hg_id=$(hg_get_branch_id)
if [[ -f "${hg_dir}/branch" ]]; then if [[ -f "${hg_dir}/branch" ]]; then
echo $(<"${hg_dir}/branch") echo $(<"${hg_dir}/branch")$hg_id
else else
echo "default" echo "default${hg_id}"
fi fi
fi fi
} }