0

Let's say for example we have a commands.sh script like the following:

#!/bin/bash

func1() {
 echo "func1"
}

# based on https://stackoverflow.com/a/16159057/12894926
"$@"

If we type ./commands.sh fu<TAB> it won't be autocompleted to ./commands.sh func1.

Is there a way to achieve this?

YFl
  • 845
  • 7
  • 22
  • use `complete -C command ...` – pynexj Jun 05 '23 at 10:43
  • Nobody would expect that the argument to _command.sh_ would be the name of a bash function. While permitted, the vast majority of program arguments are filenames. Furthermore, at the point of invoking `commands.sh`, nobody can know what functions will exist once the script runs, so even a clever completion function can not figure out how to complete this, unless you implement a specific completion system just for your _command.sh_ (similar like git completion is doing this). You can study [git completion](https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash). – user1934428 Jun 05 '23 at 11:44

0 Answers0