1006
1007
__git_complete_remote_or_refspec ()
1008
{
1009
- local cur_="$cur" cmd="${words[1]}"
1010
- local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
1009
+ local cur_="$cur" cmd="${words[__git_cmd_idx]}"
1010
+ local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0
1011
if [ "$cmd" = "remote" ]; then
1012
((c++))
1013
fi
1176
# --show-idx: Optionally show the index of the found word in the $words array.
1177
__git_find_on_cmdline ()
1178
{
1179
- local word c=1 show_idx
1179
+ local word c="$__git_cmd_idx" show_idx
1180
1181
while test $# -gt 1; do
1182
case "$1" in
1221
done
1222
local wordlist="$1"
1223
1224
- while [ $c -gt 1 ]; do
1224
+ while [ $c -gt "$__git_cmd_idx" ]; do
1225
((c--))
1226
for word in $wordlist; do
1227
if [ "$word" = "${words[c]}" ]; then
1306
local word i c=0
1307
1308
# Skip "git" (first argument)
1309
- for ((i=1; i < ${#words[@]}; i++)); do
1309
+ for ((i="$__git_cmd_idx"; i < ${#words[@]}; i++)); do
1310
word="${words[i]}"
1311
1312
case "$word" in
1442
1443
_git_branch ()
1444
{
1445
- local i c=1 only_local_ref="n" has_r="n"
1445
+ local i c="$__git_cmd_idx" only_local_ref="n" has_r="n"
1446
1447
while [ $c -lt $cword ]; do
1448
i="${words[c]}"
2474
__git_config_get_set_variables ()
2475
{
2476
local prevword word config_file= c=$cword
2477
- while [ $c -gt 1 ]; do
2477
+ while [ $c -gt "$__git_cmd_idx" ]; do
2478
word="${words[c]}"
2479
case "$word" in
2480
--system|--global|--local|--file=*)
3224
3225
_git_tag ()
3226
{
3227
- local i c=1 f=0
3227
+ local i c="$__git_cmd_idx" f=0
3228
while [ $c -lt $cword ]; do
3229
i="${words[c]}"
3230
case "$i" in
3276
_git_worktree ()
3277
{
3278
local subcommands="add list lock move prune remove unlock"
3279
- local subcommand
3279
+ local subcommand subcommand_idx
3280
3281
- subcommand="$(__git_find_on_cmdline "$subcommands")"
3281
+ subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
3282
+ subcommand_idx="${subcommand% *}"
3283
+ subcommand="${subcommand#* }"
3284
3285
case "$subcommand,$cur" in
3286
,*)
3305
# be either the 'add' subcommand, the unstuck
3306
# argument of an option (e.g. branch for -b|-B), or
3307
# the path for the new worktree.
3306
- if [ $cword -eq $((__git_cmd_idx+2)) ]; then
3308
+ if [ $cword -eq $((subcommand_idx+1)) ]; then
3309
# Right after the 'add' subcommand: have to
3310
# complete the path, so fall back to Bash
3311
# filename completion.
3329
__git_complete_worktree_paths
3330
;;
3331
move,*)
3330
- if [ $cword -eq $((__git_cmd_idx+2)) ]; then
3332
+ if [ $cword -eq $((subcommand_idx+1)) ]; then
3333
# The first parameter must be an existing working
3334
# tree to be moved.
3335
__git_complete_worktree_paths