1

I have a program foo for which I've written a bash-completion script, and that all works fine. I have dozens of wrapper-scripts bar1, bar2 ... which just sets one of the command-line options

#/usr/bin/env bash exec foo --some-option some-value "$@" 

and I was rather hoping that the completions for foo would be in operation for the wrapper scripts, but it seems not. I can generate the completion scripts for each of the wrappers of course, but that seems inelegant and wasteful. Is there some trick available to get the completion to be available in the wrappers?

3
  • You're thinking that bash would look inside bar1, see that it calls foo, so it should automatically inherit the same completions? That's asking quite a bit. Commented Aug 2, 2024 at 19:29
  • Possibly, but it is bash executing a program who's name it knows and for that name has a completion script, so not that outlandish? Commented Aug 2, 2024 at 19:34
  • But the completion doesn't happen while it's executing the script. When you're typing bar1, it doesn't even know that's a script -- script execution is handled by the OS, not the interactive shell. Commented Aug 2, 2024 at 19:38

1 Answer 1

3

try this:

_foo_completions() { # Aquí defines tus completados para `foo` COMPREPLY=( $(compgen -W "option1 option2 option3" -- "${COMP_WORDS[1]}") ) } complete -F _foo_completions foo for script in bar1 bar2 bar3; do complete -F _foo_completions "$script" done 
Sign up to request clarification or add additional context in comments.

1 Comment

That does seem to work once sourced, but when installed in /usr/local/share/bash-completions, it will only be called when foo is completed ... but I guess I can write "wrapper completions" which source it to fix that -- many thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.