Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copying bash completion (without copying the actual code)

Suppose I have a command git-local (it could be a Bash function or a binary in /usr/local/bin) and suppose I would like git-local to have the same tab completion as the command git has. Finally, suppose that I'm efficient (read lazy) and I don't want to go find the code that the git commmand uses to manually copy over and bloat my .bashrc (or whatever external file I paste it in and the source). Is there a simple way I can have git-local use the same autocompletion as git?

like image 605
Xu Wang Avatar asked Sep 16 '26 14:09

Xu Wang


1 Answers

8.7 Programmable Completion Builtins:

If the -p option is supplied, or if no options are supplied, existing completion specifications are printed in a way that allows them to be reused as input.

Something like

$(complete -p git | awk '$NF="git-local"')

maybe?

E.g.:

$ complete -p foobar
-bash: complete: foobar: no completion specification
$ complete -p traceroute
complete -F _known_hosts traceroute
$ $(complete -p traceroute | awk '$NF="foobar"')
$ complete -p foobar
complete -F _known_hosts foobar
like image 198
Adrian Frühwirth Avatar answered Sep 21 '26 16:09

Adrian Frühwirth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!