[PATCH 2 of 2] Support branch names in contrib/bash_completion

Steve Losh steve at stevelosh.com
Wed Jun 3 22:57:22 CDT 2009


# HG changeset patch
# User Steve Losh <steve at stevelosh.com>
# Date 1244084323 14400
# Node ID 964b63a89d610436b3aaa52fab8d9f4ee31b7a6e
# Parent  97543e3d136830fac258e316e3ba80392f7e1d1d
Support branch names in contrib/bash_completion

Anywhere a revision is needed a branch name can be used to specify
the tip of that branch, so branch names should be tab completed.

diff --git a/contrib/bash_completion b/contrib/bash_completion
--- a/contrib/bash_completion
+++ b/contrib/bash_completion
@@ -89,6 +89,13 @@
     COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur"))
 }
 
+_hg_branches()
+{
+    local branches="$("$hg" branches -q 2>/dev/null)"
+    local IFS=$'\n'
+    COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$branches' -- "$cur"))
+}
+
 # this is "kind of" ugly...
 _hg_count_non_option()
 {
@@ -189,9 +196,11 @@
     if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then
 	if [ $canonical = 1 ]; then
 	    _hg_tags
+	    _hg_branches
 	    return 0
 	elif [[ status != "$cmd"* ]]; then
 	    _hg_tags
+	    _hg_branches
 	    return 0
 	else
 	    return 1
@@ -207,9 +216,11 @@
 		return 0
 	    fi
 	    _hg_tags
+	    _hg_branches
 	;;
 	manifest|update)
 	    _hg_tags
+	    _hg_branches
 	;;
 	pull|push|outgoing|incoming)
 	    _hg_paths
@@ -223,6 +234,7 @@
 	;;
 	merge)
 	    _hg_tags
+	    _hg_branches
 	;;
 	commit)
 	    _hg_status "mar"
@@ -338,6 +350,7 @@
 _hg_cmd_strip()
 {
     _hg_tags
+    _hg_branches
 }
 
 _hg_cmd_qcommit()
@@ -446,6 +459,7 @@
     case "$subcmd" in
 	good|bad)
 	    _hg_tags
+	    _hg_branches
 	    ;;
     esac
 
@@ -482,6 +496,7 @@
     esac
 
     _hg_tags
+    _hg_branches
     return
 }
 
@@ -490,6 +505,7 @@
 _hg_cmd_sign()
 {
     _hg_tags
+    _hg_branches
 }
 
 
@@ -510,6 +526,7 @@
 
     # all other transplant options values and command parameters are revisions
     _hg_tags
+    _hg_branches
     return
 }
 


More information about the Mercurial-devel mailing list