Patchwork [10,of,11,V3] bash_completion: add global support for bookmarks and branches

login
register
mail settings
Submitter Sean Farley
Date Nov. 25, 2013, 5:42 p.m.
Message ID <069222d00ab0940e2afc.1385401343@dyn-160-39-236-172.dyn.columbia.edu>
Download mbox | patch
Permalink /patch/3130/
State Superseded
Headers show

Comments

Sean Farley - Nov. 25, 2013, 5:42 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1385398743 18000
#      Mon Nov 25 11:59:03 2013 -0500
# Node ID 069222d00ab0940e2afce45a7c9bfcd907e7ca44
# Parent  8284d077161322221f0df02690107b5f70c31138
bash_completion: add global support for bookmarks and branches

Previously, only -r|--rev was parsed globally which meant 'hg push -B <tab>'
would try to complete a path instead of a bookmark. Similar error for -b for
branches. Now we tab complete bookmarks and branches globally so that this
works.
Sean Farley - Nov. 26, 2013, 1:23 a.m.
On Mon, Nov 25, 2013 at 12:42 PM, Sean Farley
<sean.michael.farley@gmail.com> wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley@gmail.com>
> # Date 1385398743 18000
> #      Mon Nov 25 11:59:03 2013 -0500
> # Node ID 069222d00ab0940e2afce45a7c9bfcd907e7ca44
> # Parent  8284d077161322221f0df02690107b5f70c31138
> bash_completion: add global support for bookmarks and branches
>
> Previously, only -r|--rev was parsed globally which meant 'hg push -B <tab>'
> would try to complete a path instead of a bookmark. Similar error for -b for
> branches. Now we tab complete bookmarks and branches globally so that this
> works.
>
> diff --git a/contrib/bash_completion b/contrib/bash_completion
> --- a/contrib/bash_completion
> +++ b/contrib/bash_completion
> @@ -237,16 +237,27 @@
>      if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then
>          "_hg_cmd_$cmd"
>          return 0
>      fi
>
> -    if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then
> -        if [ $canonical = 1 ]; then
> -            _hg_labels
> -            return 0
> -        elif [[ status != "$cmd"* ]]; then
> -            _hg_labels
> +    if [ "$cmd" != status ]; then
> +        if [[ $canonical = 1 || status != "$cmd"* ]]; then
> +            case "$prev" in
> +                -r|--rev)
> +                    _hg_labels
> +                ;;
> +                -B|--bookmark)
> +                    _hg_bookmarks
> +                ;;
> +                -b|--branch)
> +                    _hg_branches
> +                ;;
> +                *)
> +                    return 1
> +                ;;
> +            esac
> +
>              return 0
>          else
>              return 1
>          fi
>      fi

I was trying to be cool and use a 'case' here but it breaks the logic.
Sad trombone. Please drop this series and I'll try again.

Patch

diff --git a/contrib/bash_completion b/contrib/bash_completion
--- a/contrib/bash_completion
+++ b/contrib/bash_completion
@@ -237,16 +237,27 @@ 
     if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then
         "_hg_cmd_$cmd"
         return 0
     fi
 
-    if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then
-        if [ $canonical = 1 ]; then
-            _hg_labels
-            return 0
-        elif [[ status != "$cmd"* ]]; then
-            _hg_labels
+    if [ "$cmd" != status ]; then
+        if [[ $canonical = 1 || status != "$cmd"* ]]; then
+            case "$prev" in
+                -r|--rev)
+                    _hg_labels
+                ;;
+                -B|--bookmark)
+                    _hg_bookmarks
+                ;;
+                -b|--branch)
+                    _hg_branches
+                ;;
+                *)
+                    return 1
+                ;;
+            esac
+
             return 0
         else
             return 1
         fi
     fi