[gentoo-dev] [PATCH] bash-completion-r1: support for aliasing completions for commands

2014-08-27 Thread Michał Górny
Hi,

One of the requirements of the completion autoloading is that there is
a file or symlink in ${completionsdir} for every completed command. For
example, if 'bakefile' completion provides completions for both
bakefile and bakefile_gen, there should be an extra symlink
from bakefile_gen to bakefile.

To make it easy to accommodate this requirements for Gentoo-originating
completions and to fix issues with upstream completions, I would like
to add a new bashcomp_alias() function.

It is to be used like:

  newbashcomp bash_completion bakefile
  bashcomp_alias bakefile bakefile_gen

or:

  bashcomp_alias emerge ebuild revdep-rebuild metagen ...

Please review.

diff -u -B -r1.13 bash-completion-r1.eclass
--- bash-completion-r1.eclass   27 Aug 2014 08:15:27 -  1.13
+++ bash-completion-r1.eclass   27 Aug 2014 14:47:01 -
@@ -116,3 +116,19 @@
newins ${@}
)
 }
+
+# @FUNCTION: bashcomp_alias
+# @USAGE: basename alias...
+# @DESCRIPTION:
+# Alias basename completion to one or more commands (aliases).
+bashcomp_alias() {
+   debug-print-function ${FUNCNAME} ${@}
+
+   [[ ${#} -lt 2 ]]  die Usage: ${FUNCNAME} basename alias...
+   local base=${1} f
+   shift
+
+   for f; do
+   dosym ${base} $(_bash-completion-r1_get_bashcompdir)/${f}
+   done
+}

-- 
Best regards,
Michał Górny


signature.asc
Description: PGP signature


Re: [gentoo-dev] [PATCH] bash-completion-r1: support for aliasing completions for commands

2014-08-27 Thread Bertrand Jacquin

Hi Michał,

On 2014-08-27 17:06, Michał Górny wrote:


Please review.



+bashcomp_alias() {
+   debug-print-function ${FUNCNAME} ${@}
+
+   [[ ${#} -lt 2 ]]  die Usage: ${FUNCNAME} basename alias...
+   local base=${1} f
+   shift
+
+   for f; do


is there a missing 'in $@ after 'for f' ? f is never initialized.


+   dosym ${base} $(_bash-completion-r1_get_bashcompdir)/${f}
+   done
+}


--
Beber



Re: [gentoo-dev] [PATCH] bash-completion-r1: support for aliasing completions for commands

2014-08-27 Thread Alexander Kapshuk
On Wed, Aug 27, 2014 at 7:01 PM, Bertrand Jacquin be...@meleeweb.net wrote:
 Hi Michał,

 On 2014-08-27 17:06, Michał Górny wrote:

 Please review.


 +bashcomp_alias() {
 +   debug-print-function ${FUNCNAME} ${@}
 +
 +   [[ ${#} -lt 2 ]]  die Usage: ${FUNCNAME} basename alias...
 +   local base=${1} f
 +   shift
 +
 +   for f; do


 is there a missing 'in $@ after 'for f' ? f is never initialized.


 +   dosym ${base}
 $(_bash-completion-r1_get_bashcompdir)/${f}
 +   done
 +}


 --
 Beber


bash(1)
for name [ [ in [ word ... ] ] ; ] do list ; done
  snip
  If the in word  is  omitted,  the  for  command
executes  list once for each positional
  parameter that is set (see PARAMETERS below).



Re: [gentoo-dev] [PATCH] bash-completion-r1: support for aliasing completions for commands

2014-08-27 Thread Alexander Kapshuk
On Wed, Aug 27, 2014 at 7:32 PM, Alexander Kapshuk
alexander.kaps...@gmail.com wrote:
 On Wed, Aug 27, 2014 at 7:01 PM, Bertrand Jacquin be...@meleeweb.net wrote:
 Hi Michał,

 On 2014-08-27 17:06, Michał Górny wrote:

 Please review.


 +bashcomp_alias() {
 +   debug-print-function ${FUNCNAME} ${@}
 +
 +   [[ ${#} -lt 2 ]]  die Usage: ${FUNCNAME} basename alias...
 +   local base=${1} f
 +   shift
 +
 +   for f; do


 is there a missing 'in $@ after 'for f' ? f is never initialized.


 +   dosym ${base}
 $(_bash-completion-r1_get_bashcompdir)/${f}
 +   done
 +}


 --
 Beber


 bash(1)
 for name [ [ in [ word ... ] ] ; ] do list ; done
   snip
   If the in word  is  omitted,  the  for  command
 executes  list once for each positional
   parameter that is set (see PARAMETERS below).

Here's a test run:
cat test4loop
#!/bin/sh
for f
do echo $f
done

sh -x test4loop 1 2 3
+ for f in '$@'
+ echo 1
1
+ for f in '$@'
+ echo 2
2
+ for f in '$@'
+ echo 3
3