5

I have a script which allows to execute Bash processes in the background, i called it "backy". Programs I want to run in background I call like this:

backy long-running-script param1 param2

The problem is now that I loose the Bash completion for long-running-script if I prepend another script.

I want to write a Bash completion file which preserves not only the Bash completion for long-running-script and all of its parameters, also for every other script that I want to call with backy.

I have some experience with Bash completion, but I'm just missing the command which I can insert into my Bash completion script so that it completes with the completion of the script that is to be called. Any ideas?

My completion so far:

have backy &&
_backy_complete()
{
  local cur prev goals

  COMPREPLY=()
  cur=${COMP_WORDS[COMP_CWORD]}

  # How to get the completion from the script that is the param for backy, 
  # in a generic way?
  COMPREPLY=( ????? )
  return 0
} &&
complete -F _backy_complete backy

EDIT - SOLUTION:

Thanks to Lekensteyn, I replaced the content of my existing bash completion script with just this line:

complete -F _command backy
Wolkenarchitekt
  • 20,170
  • 29
  • 111
  • 174
  • You do not have to add the solution to your question, since it appears straight in the answer under the question. – Lekensteyn Sep 01 '11 at 14:58

1 Answers1

4

There is already a bash_completion function for such cases:

complete -F _command backy

It's used for autocompleting the commands after sudo, fakeroot and others. Any arguments passed to backy are ignored like:

backy --whatever --this --is=ignored not ignored anymore
Lekensteyn
  • 64,486
  • 22
  • 159
  • 192