Skip to content

Commit

Permalink
Display current mercurial bookmark, if any
Browse files Browse the repository at this point in the history
Mercurial bookmarks are more similar to how Git branches work than
Mercurial branches. This will display both if a bookmark is active.

Co-authored-by: Étienne Deparis <etienne@depar.is>
  • Loading branch information
Rycieos and milouse committed Nov 25, 2020
1 parent 1a9fcd0 commit f4636e6
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions liquidprompt
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,12 @@ _lp_vcs_details_color() {
local branch
if _lp_vcs_branch; then
branch="$lp_vcs_branch"

if _lp_vcs_bookmark; then
branch+=": $lp_vcs_bookmark"
fi
elif _lp_vcs_bookmark; then
branch="$lp_vcs_bookmark"
elif _lp_vcs_tag; then
branch="tag: $lp_vcs_tag"
else
Expand Down Expand Up @@ -1046,6 +1052,14 @@ _lp_vcs_branch() {
_lp_${lp_vcs_type}_branch 2>/dev/null
}

# Get the bookmark name of the repo in the current directory.
# Most VCS providers don't support this.
# return: true if a valid VCS bookmark is active.
# lp_vcs_bookmark; the name of the current bookmark.
_lp_vcs_bookmark() {
_lp_${lp_vcs_type}_bookmark 2>/dev/null
}

# Get a tag name of the repo in the current directory. Note that not all VCS
# providers support tags that match to one and only one commit object.
# return: true if a valid VCS tag matches the HEAD commit. False if no tag
Expand Down Expand Up @@ -1333,8 +1347,8 @@ _lp_hg_active() {

# Get the branch name of the Mercurial repo in the current directory.
# Note that Mercurial commits are always "on a branch", so checking out a
# non-head commit will still return a branch name.
# TODO: support bookmarks, maybe replace hg branch
# non-head commit will still return a branch name. A closer analog to Git
# branches are Mercurial bookmarks.
# return: true if a valid Mercurial branch is checked out.
# lp_vcs_branch; the name of the current branch.
_lp_hg_branch() {
Expand All @@ -1350,6 +1364,20 @@ _lp_hg_branch() {
fi
}

# Get the bookmark name of the Mercurial repo in the current directory.
# Mercurial bookmarks work more like Git branches.
# return: true if a valid Mercurial bookmark is checked out.
# lp_vcs_bookmark; the name of the current bookmark.
_lp_hg_bookmark() {
local bookmark ret
if bookmark="$(\hg bookmark --list --quiet . 2>/dev/null)"; then
__lp_escape "$bookmark"
lp_vcs_bookmark="$ret"
else
return 1
fi
}

# Get the most recent tag that refers to the current revision.
# return: true if a valid Mercurial tag is checked out.
# lp_vcs_tag; the name of the current tag.
Expand Down

0 comments on commit f4636e6

Please sign in to comment.