-
Notifications
You must be signed in to change notification settings - Fork 400
Augment an existing completion function with my own #1400
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
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
-
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
Beta Was this translation helpful? Give feedback.
All reactions
-
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`.
Beta Was this translation helpful? Give feedback.