Skip to content

Implement hg prompt #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion lib/vcsstatus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ zstyle ':vcs_info:*' max-exports 5

# To be enable check-for-changes with hg.
zstyle ':vcs_info:hg:*' get-revision true
zstyle ':vcs_info:hg*:*' 'check-for-changes' true
zstyle ':vcs_info:(git|hg|bzr):*' use-simple true
zstyle ':vcs_info:hg*' actionformats "(%s|%a)[%i%u %b %m]"

## Set formats.
#
Expand All @@ -54,7 +56,7 @@ zstyle ':vcs_info:(git|hg|bzr):*' use-simple true
zstyle ':vcs_info:*' formats '%s' '%b' '%m'
zstyle ':vcs_info:*' actionformats '%s' '%b' '%m' '%a'

zstyle ':vcs_info:(git|hg):*' check-for-changes false
zstyle ':vcs_info:(git):*' 'check-for-changes' false


# Check zsh version.
Expand Down Expand Up @@ -85,7 +87,13 @@ function _zsh_vcs_prompt_vcs_detail_info() {

# Get git status.
if is-at-least 4.3.11; then
if [ "$vcs_name" = 'git' ]; then
git_status=$vcs_info_msg_2_
else
if [ "$vcs_name" = 'hg' ]; then
git_status=$(_zsh_vcs_prompt_get_hg_status)\
fi
fi
else
if [ "$vcs_name" = 'git' ]; then
git_status=$(_zsh_vcs_prompt_get_git_status "$vcs_branch_name")
Expand All @@ -109,6 +117,38 @@ function +vi-git-hook-detail-info() {
return 0
}

function _zsh_vcs_prompt_get_hg_status() {
local outgoing
local incoming
local clean

outgoing=$(hg prompt '{outgoing|count}')
if [ -z "$outgoing" ]; then
outgoing='0'
fi
echo $outgoing

incoming=$(hg prompt '{incoming|count}')
if [ -z "$incoming" ]; then
incoming='0'
fi
echo $incoming
echo 0
echo 0
echo 0
echo 0
echo 0

clean=$(hg prompt '{status}')
if [ "$clean" = "!" ]; then
clean=0
else
clean=1
fi;
echo $clean
echo 0
}

# $1 : Branch name.
function _zsh_vcs_prompt_get_git_status() {
local branch_name=$1
Expand Down
4 changes: 2 additions & 2 deletions zshrc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ function _zsh_vcs_prompt_update_vcs_status() {

# Select formats.
local used_formats
if [ "$vcs_name" = 'git' ]; then
if [ "$vcs_name" = 'git' -o "$vcs_name" = 'hg' ]; then
used_formats=$ZSH_VCS_PROMPT_GIT_ACTION_FORMATS
# Check action.
if [ -z "$action" -o "$action" = '0' ]; then
Expand All @@ -341,7 +341,7 @@ function _zsh_vcs_prompt_update_vcs_status() {
fi

# Escape slash '/'.
branch=$(echo "$branch" | sed 's%/%\\/%g')
branch=$(echo "$branch" | sed 's%/%\\/%')
# Set unmerged count.
if [ -n "$unmerged" -a "$unmerged" != '0' ]; then
branch="${branch}(${unmerged})"
Expand Down