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

login
register
mail settings
Submitter Sean Farley
Date Nov. 26, 2013, 1:37 a.m.
Message ID <4bc4c6db0b2a3d027a5b.1385429836@laptop.local>
Download mbox | patch
Permalink /patch/3151/
State Superseded
Headers show

Comments

Sean Farley - Nov. 26, 2013, 1:37 a.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 4bc4c6db0b2a3d027a5b689452cd9cf135e17840
# 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, 8:37 p.m.
On Mon, Nov 25, 2013 at 7:37 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 4bc4c6db0b2a3d027a5b689452cd9cf135e17840
> # 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,17 +237,26 @@
>      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
> -            return 0
> +    if [ "$cmd" != status ]; then
> +        if [[ $canonical = 1 || status != "$cmd"* ]]; then
> +            case "$prev" in
> +                -r|--rev)
> +                    _hg_labels
> +                    return 0
> +                ;;
> +                -B|--bookmark)
> +                    _hg_bookmarks
> +                    return 0
> +                ;;
> +                -b|--branch)
> +                    _hg_branches
> +                    return 0
> +                ;;
> +            esac
>          else
>              return 1
>          fi
>      fi
>

Since I kept making mistakes in the if-else logic of this patch, I've
gone ahead and broken it up into multiple patches that make it much
clearer. So, once again, drop this series and I'll resend.

Patch

diff --git a/contrib/bash_completion b/contrib/bash_completion
--- a/contrib/bash_completion
+++ b/contrib/bash_completion
@@ -237,17 +237,26 @@ 
     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
-            return 0
+    if [ "$cmd" != status ]; then
+        if [[ $canonical = 1 || status != "$cmd"* ]]; then
+            case "$prev" in
+                -r|--rev)
+                    _hg_labels
+                    return 0
+                ;;
+                -B|--bookmark)
+                    _hg_bookmarks
+                    return 0
+                ;;
+                -b|--branch)
+                    _hg_branches
+                    return 0
+                ;;
+            esac
         else
             return 1
         fi
     fi