bf9645224b529be0e03655b4cef9c32f66c76015

Author
Philipp Tessenow <philipp@tessenow.org>
Committer
Philipp Tessenow <philipp@tessenow.org>
Date

Message

extend mercurial plugin to be more like git/svn

implement in_hg(), hg_get_branch_name(), hg_prompt_info(), and hg_dirty() for the mercurial plugin
named functions similar to subversion plugin, to give theme maintainers an easier life

Diff

 1diff --git a/plugins/mercurial/mercurial.plugin.zsh b/plugins/mercurial/mercurial.plugin.zsh
 2index 9aa2d167aa6fb40c01189556beb000b2862b3f85..83dd578b3195db80ed2c2c975220f3e3dc5653ce 100644
 3--- a/plugins/mercurial/mercurial.plugin.zsh
 4+++ b/plugins/mercurial/mercurial.plugin.zsh
 5@@ -17,8 +17,40 @@ alias hgs='hg status'
 6 # this is the 'git commit --amend' equivalent
 7 alias hgca='hg qimport -r tip ; hg qrefresh -e ; hg qfinish tip'
 8 
 9-function hg_current_branch() {
10-  if [ -d .hg ]; then
11-    echo hg:$(hg branch)
12+function in_hg() {
13+  if [[ -d .hg ]] || $(hg summary > /dev/null 2>&1); then
14+    echo 1
15   fi
16 }
17+
18+function hg_get_branch_name() {
19+  if [ $(in_hg) ]; then
20+    echo $(hg branch)
21+  fi
22+}
23+
24+function hg_prompt_info {
25+  if [ $(in_hg) ]; then
26+    _DISPLAY=$(hg_get_branch_name)
27+    echo "$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_HG_PROMPT_PREFIX\
28+$ZSH_THEME_REPO_NAME_COLOR$_DISPLAY$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_HG_PROMPT_SUFFIX$ZSH_PROMPT_BASE_COLOR$(hg_dirty)$ZSH_PROMPT_BASE_COLOR"
29+    unset _DISPLAY
30+  fi
31+}
32+
33+function hg_dirty_choose {
34+  if [ $(in_hg) ]; then
35+    hg status 2> /dev/null | grep -Eq '^\s*[ACDIM!?L]'
36+    if [ $pipestatus[-1] -eq 0 ]; then
37+      # Grep exits with 0 when "One or more lines were selected", return "dirty".
38+      echo $1
39+    else
40+      # Otherwise, no lines were found, or an error occurred. Return clean.
41+      echo $2
42+    fi
43+  fi
44+}
45+
46+function hg_dirty {
47+  hg_dirty_choose $ZSH_THEME_HG_PROMPT_DIRTY $ZSH_THEME_HG_PROMPT_CLEAN
48+}