Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Augment an existing completion function with my own #1400

Answered by akinomyoga
dhalbert asked this question in Q&A
Discussion options

bash-completion supplies a make script with a completion function for the make command. For example, make <TAB> lists available targets in the Makefile. I want to preserve that functionality, and add an additional completion function, which is specific to my build environment, something like make SOMEVAR=<optprefix><tab>.

I already have the function working. But if I complete -F _myfunction make, then I override the one supplied by bash-completion. How can I cascade or augment the existing one so that both work? Thanks. I've looked here and in various stackexchange sites, to no avail.

You must be logged in to vote

You can call the bash-completion function at the beginning of _myfunction.

# For bash-completion >= 2.12
_comp_load make
_myfunction() {
 _comp_cmd_make "$@"
 # ...
 COMPREPLY+=(...)
}
complete -F _myfunction make
# For bash-completion < 2.12
__load_completion make
_myfunction() {
 _make "$@"
 # ...
 COMPREPLY+=(...)
}
complete -F _myfunction make

Replies: 1 comment 1 reply

Comment options

You can call the bash-completion function at the beginning of _myfunction.

# For bash-completion >= 2.12
_comp_load make
_myfunction() {
 _comp_cmd_make "$@"
 # ...
 COMPREPLY+=(...)
}
complete -F _myfunction make
# For bash-completion < 2.12
__load_completion make
_myfunction() {
 _make "$@"
 # ...
 COMPREPLY+=(...)
}
complete -F _myfunction make
You must be logged in to vote
1 reply
Comment options

Thank you very much. I had to use __load_completion, based on the version of `bash-completion in Ubuntu 24.04.

One mistake I made initially applying this was to put my augmentation script into ~/.local/share/bash-completion/completions/make. That doesn't work because then __load_completion finds my script first, based on search order, and loads it again. The bash-completion script for make is therefore skipped. So I put my script elsewhere and sourced it "manuallyin.bashrc`.

Answer selected by dhalbert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /