[PATCH] contrib: some support for named branches in zsh_completion (issue2988)

Ben Hockey neonstalwart at gmail.com
Wed Sep 14 15:31:21 CDT 2011


# HG changeset patch
# User Ben Hockey <neonstalwart at gmail.com>
# Date 1315405466 14400
# Node ID 2e033d33982cb9c4ece5bab342f63284da08a9e1
# Parent  bfe903b1ff4eaa081ff4374b6d3744a0936b928e
contrib: some support for named branches in zsh_completion (issue2988)

named branches were not included for autocompletion in zsh.  by adding
_hg_branches and calling it from _hg_labels, named branches are now included
when autocompleting many commands in zsh.  support for completion of hg log -b
was also added.  there are possibly other cases where support needs to be
explicitly added.

diff --git a/contrib/zsh_completion b/contrib/zsh_completion
--- a/contrib/zsh_completion
+++ b/contrib/zsh_completion
@@ -160,16 +160,17 @@ _hg_commands() {
 _hg_revrange() {
   compset -P 1 '*:'
   _hg_labels "$@"
 }
 
 _hg_labels() {
   _hg_tags "$@"
   _hg_bookmarks "$@"
+  _hg_branches "$@"
 }
 
 _hg_tags() {
   typeset -a tags
   local tag rev
 
   _hg_cmd tags | while read tag
   do
@@ -186,16 +187,27 @@ _hg_bookmarks() {
     if test -z ${bookmark[-1]:#[0-9]*}
     then
       bookmarks+=($bookmark[-2])
     fi
   done
   (( $#bookmarks )) && _describe -t bookmarks 'bookmarks' bookmarks
 }
 
+_hg_branches() {
+  typeset -a branches
+  local branch
+
+  _hg_cmd branches | while read branch
+  do
+    branches+=(${branch/ #    [0-9]#:*})
+  done
+  (( $#branches )) && _describe -t branches 'branches' branches
+}
+
 # likely merge candidates
 _hg_mergerevs() {
   typeset -a heads
   local myrev
 
   heads=(${(f)"$(_hg_cmd heads --template '{rev}\\n')"})
   # exclude own revision
   myrev=$(_hg_cmd log -r . --template '{rev}\\n')
@@ -612,16 +624,17 @@ _hg_cmd_log() {
   '(--copies -C)'{-C,--copies}'[show copied files]' \
   '(--keyword -k)'{-k+,--keyword}'[search for a keyword]:' \
   '(--limit -l)'{-l+,--limit}'[limit number of changes displayed]:' \
   '*'{-r,--rev}'[show the specified revision or range]:revision:_hg_revrange' \
   '(--no-merges -M)'{-M,--no-merges}'[do not show merges]' \
   '(--only-merges -m)'{-m,--only-merges}'[show only merges]' \
   '(--patch -p)'{-p,--patch}'[show patch]' \
   '(--prune -P)'{-P+,--prune}'[do not display revision or any of its ancestors]:revision:_hg_labels' \
+  '(--branch -b)'{-b+,--branch}'[show changesets within the given named branch]:branch:_hg_branches' \
   '*:files:_hg_files'
 }
 
 _hg_cmd_manifest() {
   _arguments -s -w : $_hg_global_opts \
   ':revision:_hg_labels'
 }
 


More information about the Mercurial-devel mailing list