git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 0/1] completion: Dynamic completion loading

From
Florian Gamböck <mail@floga.de>
Date
Apr 8, 2018, 18:26 UTC
Message-ID
<20180408182552.26289-1-mail@floga.de>

In this small patch I want to introduce a way to dynamically load completion scripts for external subcommands.

A few years ago, you would put a completion script (which defines a Bash function _git_foo for a custom git subcommand foo) into /etc/bash_completion.d, or save it somewhere in your $HOME and source it manually in your .bashrc.

Starting with bash-completion v2.0 (or, to be absolutely exact, the preview versions started at v1.90), completion scripts are not sourced at bash startup anymore. Rather, when typing in a command and trigger completion by pressing the TAB key, the new bash-completion's main script looks for a script with the same name as the typed command in the completion directory, sources it, and provides the completions defined in this script.

However, that only works for top level commands. After a completion script has been found, the logic is delegated to this script. This means, that the completion of subcommands must be handled by the corresponding completion script.

As it is now, git is perfectly able to call custom completion functions, iff they are already defined when calling the git completion. With my patch, git uses an already defined loader function of bash-completion (or continues silently if this function is not found), loads an external completion script, and provides its completions.

An example for an external completion script would be /usr/share/bash-completion/completions/git-foo for a git subcommand foo.

Florian Gamböck (1):
  completion: Load completion file for external subcommand
 contrib/completion/git-completion.bash | 8 ++++++++
 1 file changed, 8 insertions(+)
-- 
2.16.1
Next: Florian Gamböck
Message 1 of 13 in “completion: Dynamic completion loading”
  1. 0/1 completion: Dynamic completion loadingFlorian Gamböck, Apr 8, 2018
  2. 1/1 completion: Load completion file for external subcommandFlorian Gamböck, Apr 8, 2018
  3. Florian GamböckApr 8, 2018
  4. Stefan BellerApr 9, 2018
  5. Florian GamböckApr 9, 2018
  6. SZEDER GáborApr 19, 2018
  7. 1/1 completion: load completion file for external subcommandFlorian Gamböck, Apr 8, 2018
  8. Junio C HamanoApr 8, 2018
  9. Florian GamböckApr 9, 2018
  10. Junio C HamanoApr 9, 2018
  11. Florian GamböckApr 9, 2018
  12. Junio C HamanoApr 9, 2018
  13. Florian GamböckApr 10, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.