From e3977e439c660a76abc6d5d3c2191abf24405494 Mon Sep 17 00:00:00 2001 From: Romain Failliot Date: Sun, 18 Feb 2018 19:15:36 -0500 Subject: [PATCH] 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`. --- plugins/mercurial/mercurial.plugin.zsh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/mercurial/mercurial.plugin.zsh b/plugins/mercurial/mercurial.plugin.zsh index 592a7f02..db7649fd 100644 --- a/plugins/mercurial/mercurial.plugin.zsh +++ b/plugins/mercurial/mercurial.plugin.zsh @@ -38,13 +38,23 @@ function in_hg() { 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() { local hg_dir=$(hg_get_dir) if [[ $hg_dir != "" ]]; then + local hg_id=$(hg_get_branch_id) if [[ -f "${hg_dir}/branch" ]]; then - echo $(<"${hg_dir}/branch") + echo $(<"${hg_dir}/branch")$hg_id else - echo "default" + echo "default${hg_id}" fi fi }