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

Re: [PATCH] completion: Handle '!f() { ... }; f' aliases

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jun 8, 2014, 09:02 UTC
Message-ID
<CAPig+cQKtVoc7X2SBE8L1pSpnwQxkmFF6pL2PL-7RUoFq5h8gw@mail.gmail.com>
In-Reply-To
<1402150221-25548-1-git-send-email-prohaska@zib.de>
On Sat, Jun 7, 2014 at 10:10 AM, Steffen Prohaska <prohaska@zib.de> wrote:
Show 30 quoted lines
> '!f() { ... }; f' is a recommended pattern to declare more complex
> aliases (see git wiki [1]).  This commit teaches the completion to
> handle them.
>
> When determining which completion to use for an alias, the opening brace
> is now ignored in order to continue the search for a git command inside
> the function body.  For example, the alias '!f() { git commit ... }' now
> triggers commit completion.  Previously, the search stopped on '{', and
> the completion tried it to determine how to complete, which obviously
> was useless.
>
> Furthermore, the null command ':' is now skipped, so that it can be used
> as a workaround to declare the desired completion style.  For example,
> the alias '!f() { : git commit ; if ...  ' now triggers commit
> completion.
>
> [1] https://git.wiki.kernel.org/index.php/Aliases
>
> Signed-off-by: Steffen Prohaska <prohaska@zib.de>
> ---
> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
> index 2d4beb5..ea48681 100755
> --- a/t/t9902-completion.sh
> +++ b/t/t9902-completion.sh
> @@ -550,6 +550,26 @@ test_expect_success 'complete files' '
>         test_completion "git add mom" "momified"
>  '
>
> +test_expect_success 'completion uses <cmd> completion for alias !f() { VAR=val git <cmd> ... }' '
> +       git config alias.co "!f() { VAR=val git checkout ... ; } f" &&

test_config would be an appropriate replacement for "git config" + "git config --unset".

Show 10 quoted lines
> +       test_completion "git co m" <<-\EOF &&
> +       master Z
> +       mybranch Z
> +       mytag Z
> +       EOF
> +       git config --unset alias.co
> +'
> +
> +test_expect_success 'completion used <cmd> completion for alias !f() { : git <cmd> ; ... }' '
> +       git config alias.co "!f() { : git checkout ; if ... } f" &&
Ditto.
Show 13 quoted lines
> +       test_completion "git co m" <<-\EOF &&
> +       master Z
> +       mybranch Z
> +       mytag Z
> +       EOF
> +       git config --unset alias.co
> +'
> +
>  test_expect_failure 'complete with tilde expansion' '
>         git init tmp && cd tmp &&
>         test_when_finished "cd .. && rm -rf tmp" &&
> --
> 2.0.0.244.g4e8e734
Previous: Steffen ProhaskaNext: Steffen Prohaska
Message 2 of 6 in “completion: Handle '!f() { ... }; f' aliases”
  1. completion: Handle '!f() { ... }; f' aliasesSteffen Prohaska, Jun 7, 2014
  2. Eric SunshineJun 8, 2014
  3. completion: Handle '!f() { ... }; f' aliasesSteffen Prohaska, Jun 9, 2014
  4. Junio C HamanoJun 10, 2014
  5. Steffen ProhaskaJun 12, 2014
  6. completion: Handle '!f() { ... }; f' and "!sh -c '...'" aliasesSteffen Prohaska, Jun 12, 2014

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.