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

[PATCH v3 0/4] completion: make __git_complete public

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Dec 30, 2020, 23:29 UTC
Message-ID
<20201230232950.582152-1-felipe.contreras@gmail.com>

Back in 2012 I argued [1] for the introduction of a helper that would allow users to specify aliases like:

  git_complete gf git_fetch

There was pushback because there was no clear guideline for public functions (git_complete vs. _git_complete vs. _GIT_complete), and some aliases didn't actually work.

Fast-forward to 2020, and there's still no guideline for public functions, and those aliases still don't work (even though I sent the fixes).

This has not prevented people from using this function that is clearly needed to setup custom aliases [2], and in fact that's the recommended way since there's no other.

But it is cumbersome that the user must type:
  __git_complete gf _git_fetch
Or worse:
  __git_complete gk __gitk_main

8 years is more than enough time to stop waiting for the perfect to come; let's define a public function (with the same name) that is actually user-friendly:

  __git_complete gf git_fetch
  __git_complete gk gitk
While also maintaining backwards compatibility.
Changes since v2:
 * Improved the safety of __git_have_func with suggestions from René Scharfe
 * Added documentation to the top of git-completion.bash

[1] https://lore.kernel.org/git/1334524814-13581-1-git-send-email-felipe.contreras@gmail.com/ [2] https://stackoverflow.com/questions/342969/how-do-i-get-bash-completion-to-work-with-aliases

Felipe Contreras (4):
  completion: bash: add __git_have_func helper
  completion: bash: improve function detection
  test: completion: add tests for __git_complete
  completion: add proper public __git_complete
 contrib/completion/git-completion.bash | 50 ++++++++++++++++++++------
 t/t9902-completion.sh                  | 20 +++++++++++
 2 files changed, 60 insertions(+), 10 deletions(-)
Range-diff against v2:
1:  0993732142 = 1:  0993732142 completion: bash: add __git_have_func helper
-:  ---------- > 2:  6a3fe8b79b completion: bash: improve function detection
2:  7918c34d0e = 3:  b211eebc0d test: completion: add tests for __git_complete
3:  8a6cc52063 ! 4:  a5bfe5376b completion: add proper public __git_complete
    @@ Commit message
         Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
     
      ## contrib/completion/git-completion.bash ##
    +@@
    + # tell the completion to use commit completion.  This also works with aliases
    + # of form "!sh -c '...'".  For example, "!sh -c ': git commit ; ... '".
    + #
    ++# If you have a command that is not part of git, but you would still
    ++# like completion, you can use __git_complete:
    ++#
    ++#   __git_complete gl git_log
    ++#
    ++# Or if it's a main command (i.e. git or gitk):
    ++#
    ++#   __git_complete gk gitk
    ++#
    + # Compatible with bash 3.2.57.
    + #
    + # You can set the following environment variables to influence the behavior of
     @@ contrib/completion/git-completion.bash: __git_func_wrap ()
      	$1
      }
-- 
2.30.0
Next: Felipe Contreras
Message 1 of 5 in “completion: make __git_complete public”
  1. 0/4 completion: make __git_complete publicFelipe Contreras, Dec 30, 2020
  2. 2/4 completion: bash: improve function detectionFelipe Contreras, Dec 30, 2020
  3. 1/4 completion: bash: add __git_have_func helperFelipe Contreras, Dec 30, 2020
  4. 3/4 test: completion: add tests for __git_completeFelipe Contreras, Dec 30, 2020
  5. 4/4 completion: add proper public __git_completeFelipe Contreras, Dec 30, 2020

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.