Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preserve Bash Completion for all commands that are prepended by a custom command

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
like image 225
Wolkenarchitekt Avatar asked Oct 12 '22 05:10

Wolkenarchitekt


1 Answers

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
like image 190
Lekensteyn Avatar answered Oct 14 '22 21:10

Lekensteyn