3

I'm trying to write a wrapper script around another program (e.g. foo_wrapper around foo), which simply overrides some flags on every call to foo. I want users to be able to interact with foo_wrapper and foo exactly the same way, including seeing the same bash completion output.

For example, foo_wrapper.sh should simply add --my_flag on every call to foo, but it's not enough to simply prepend or append flags to the argument list, it has to put them in the right location because of the way foo is implemented. So if the user calls foo_wrapper bar baz, I want it to map to foo bar --my_flag baz. This is why I assume I cannot simply use a bash alias.

This would be a simple script if I didn't need bash completion to work, but without bash completion this thing is not going to be nearly as useful. Can anyone help me figure out what to do here? I discovered the compgen builtin for bash, but I'm having trouble seeing how/if I can use it for this.

codeforester
  • 39,467
  • 16
  • 112
  • 140
karagog
  • 138
  • 1
  • 6
  • 2
    Is your real question how to implement bash completion for your wrapper? I would start with the bash completion for the thing you're wrapping, and just add your extra piece. – Rob Napier May 16 '18 at 00:15
  • You don't want exactly the same completion output, though, right? `foo` completion will offer `--my_flag`, but you don't want to see that in the completion for `foo_wrapper`. – Benjamin W. May 16 '18 at 02:35
  • 2
    Possibly relevant: https://stackoverflow.com/questions/30537074/use-compgen-to-get-autocomplete-for-another-command-which-flag-to-use/30541042 – rici May 16 '18 at 02:47

0 Answers0