0

I'm writing a script wrapping a certain Linux command. Now, that command, when I use it directly on the command-line, has some autocomplete behavior. For example, if I type the command name, then space, then a string and press Tab - it gets completed into the name of an executable on the path. However, the wrapper script does not seem to have this behavior. How can I get bash to use the same auto-completion for my wrapper as for the original command?

To make things more concrete: The command is which. I'm writing a wrapper which invokes it, and if it didn't fail, executes readlink -f on the result of which. I would like auto-complete to find the executable on the path, as it does for which.

1 Answer 1

1

You can list the completion spec for which with

complete -p which

The result is complete -c which. So if you have your own new command mywhich, executable, in the PATH, then you can have it complete in the same way by configuring bash with

complete -c mywhich

You can put this line in ~/.bash_completion

3
  • That doesn't seem to make a lot of sense, since supposedly it says that bash will run which in a subshell and use its output for completion
    – einpoklum
    Commented Jan 18 at 18:59
  • I must not have understood what you want to do. complete -c <name-of-a-command> is like -A command and means look through all the available commands (in PATH) to create the list of possible completions.
    – meuh
    Commented Jan 18 at 20:10
  • No, you have understood, it just looked like a kind of recursive thing: complete -switch something produces complete -switch something ...
    – einpoklum
    Commented Jan 18 at 21:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .