pr-2155/mobilutz/zsh-complete-global-C-v1
pr-2155/mobilutz/zsh-complete-global-C-v1: completion: zsh: support completion after "git -C <path>"
tagged this
17 Jun 15:30
From: Lutz Lengemann <lutz@lengemann.net>
The zsh completion wrapper (__git_zsh_main) did not handle the global -C
option, so "git -C <path> <command> <TAB>" offered nothing and could not
complete a command's arguments.
Three things are needed to make it work, all scoped to -C:
- Add -C to the _arguments specification, so completion no longer stops
at it.
- Advance __git_cmd_idx past any leading "-C <path>" options. The index
is hard-coded to 1, i.e. the command is assumed to be the first
argument; with -C present the command sits two words later for each
-C, so the bash helpers otherwise look at the wrong word and produce
nothing.
- Collect the -C paths into __git_C_args, as __git_main does. The bash
helpers run git to resolve aliases and list refs; without the -C
paths they run in the current directory, so completion fails whenever
the cwd is not the target repository or the command is an alias.
With these, "git -C <path> <command> <TAB>" completes the command, its
options and its arguments, including outside the repository, through
aliases, and with repeated -C options.
Signed-off-by: Lutz Lengemann <lutz@lengemann.net>
Submitted-As: https://lore.kernel.org/git/pull.2155.git.1781710256081.gitgitgadget@gmail.com