Patchwork [3,of,7] bash_completion: determine root executable in case of alias

login
register
mail settings
Submitter Sean Farley
Date Nov. 21, 2013, 10:56 p.m.
Message ID <d43f240774e9ca3acb00.1385074567@laptop.local>
Download mbox | patch
Permalink /patch/3082/
State Superseded
Commit 191ab08e70993229fb6fe12f3dba2148fbc9ebae
Headers show

Comments

Sean Farley - Nov. 21, 2013, 10:56 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1384971595 18000
#      Wed Nov 20 13:19:55 2013 -0500
# Node ID d43f240774e9ca3acb00d49584c192f0d47b4de5
# Parent  cac5a729db513d9fe374157d4ce225a6cd22149b
bash_completion: determine root executable in case of alias

This solves an issue for users that have "alias hg='hg --some_opts'" where they
would see wrong entries in the completion output (such as color codes).
Sean Farley - Nov. 22, 2013, 7:48 p.m.
On Thu, Nov 21, 2013 at 5:56 PM, Sean Farley
<sean.michael.farley@gmail.com> wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley@gmail.com>
> # Date 1384971595 18000
> #      Wed Nov 20 13:19:55 2013 -0500
> # Node ID d43f240774e9ca3acb00d49584c192f0d47b4de5
> # Parent  cac5a729db513d9fe374157d4ce225a6cd22149b
> bash_completion: determine root executable in case of alias
>
> This solves an issue for users that have "alias hg='hg --some_opts'" where they
> would see wrong entries in the completion output (such as color codes).
>
> diff --git a/contrib/bash_completion b/contrib/bash_completion
> --- a/contrib/bash_completion
> +++ b/contrib/bash_completion
> @@ -128,16 +128,23 @@
>      echo $(($count - 1))
>  }
>
>  _hg()
>  {
> -    local cur prev cmd cmd_index opts i
> +    local cur prev cmd cmd_index opts i aliashg
>      # global options that receive an argument
>      local global_args='--cwd|-R|--repository'
>      local hg="$1"
>      local canonical=0
>
> +    aliashg=$(alias $hg 2>/dev/null)
> +    if [[ -n "$aliashg" ]]; then
> +      aliashg=${aliashg#"alias $hg='"}
> +      aliashg=${aliashg%"'"}
> +      hg=$aliashg
> +    fi
> +
>      COMPREPLY=()
>      cur="$2"
>      prev="$3"
>
>      # searching for the command
> diff --git a/setup.py b/setup.py
> --- a/setup.py
> +++ b/setup.py
> @@ -573,5 +573,6 @@
>                     bdist_mpkg=dict(zipdist=True,
>                                     license='COPYING',
>                                     readme='contrib/macosx/Readme.html',
>                                     welcome='contrib/macosx/Welcome.html')),
>        **extra)
> +asdf

Because of this typo and the fact that I have another patch to go in
this series, please ignore this for now. I'll resend another version.

Patch

diff --git a/contrib/bash_completion b/contrib/bash_completion
--- a/contrib/bash_completion
+++ b/contrib/bash_completion
@@ -128,16 +128,23 @@ 
     echo $(($count - 1))
 }
 
 _hg()
 {
-    local cur prev cmd cmd_index opts i
+    local cur prev cmd cmd_index opts i aliashg
     # global options that receive an argument
     local global_args='--cwd|-R|--repository'
     local hg="$1"
     local canonical=0
 
+    aliashg=$(alias $hg 2>/dev/null)
+    if [[ -n "$aliashg" ]]; then
+      aliashg=${aliashg#"alias $hg='"}
+      aliashg=${aliashg%"'"}
+      hg=$aliashg
+    fi
+
     COMPREPLY=()
     cur="$2"
     prev="$3"
 
     # searching for the command
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -573,5 +573,6 @@ 
                    bdist_mpkg=dict(zipdist=True,
                                    license='COPYING',
                                    readme='contrib/macosx/Readme.html',
                                    welcome='contrib/macosx/Welcome.html')),
       **extra)
+asdf