From patchwork Tue Apr 20 09:19:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 12213591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C735FC433ED for ; Tue, 20 Apr 2021 09:20:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 953CF61057 for ; Tue, 20 Apr 2021 09:20:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231370AbhDTJUh (ORCPT ); Tue, 20 Apr 2021 05:20:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231318AbhDTJUd (ORCPT ); Tue, 20 Apr 2021 05:20:33 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1C61C06174A for ; Tue, 20 Apr 2021 02:20:01 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id f2-20020a17090a4a82b02900c67bf8dc69so22021732pjh.1 for ; Tue, 20 Apr 2021 02:20:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C4QUn1MJIiiv9bTaQ/vinfQ4bodzXgbz7zi1f29rVwY=; b=QKLHPgNH7kLva+IbHpN4J67AnIa6fbIiw4zdrNgxfCiSKCJKfhYHNQrjQZEUy3WYQG 0rLklpNzym5PGyWtFUvV/p7r+wGbkBfssvZ5d5ssl7aMKlbwKquyR634e3RgDCBovfSL 2yokR3+6qiaF2NoR+9Sa1yyrgq2Wgyh7qGa7E6iNxlJJf+jku8Moh4E3fWhU/TWXc5+Q xtt6aucg3qZK4HXWNc6rm6Q1XpV8grBBK7DQDZPLYwj749uKc2pJg+H2zrvAiOMjVIwK xp+NouQeZB1bMaKTM+vuZMBWiVoLieNd6WND5sW10ct4tSPMWB9x1wMgm63WH8Bx8Vle 7rpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C4QUn1MJIiiv9bTaQ/vinfQ4bodzXgbz7zi1f29rVwY=; b=DQzCQWQfXrMH/VyObJibNFfFjgL7pvuNkos/7+EA+qcvBkDZYvxuvJq1S+9Hb3juPY p2hkY1vRUXZX5DMf8CjsE1x/Ewqwb/1gUjQtlQAUtPWncAstCnwuqKsQTGBxRAwSF3m2 PHbw0XvZt9cfnBl29TRnnFwcbNRwtveN9ApJuggYDoDrJjimRlrAgbKxuzh8/bGcFA5U nF4nq7sB2q4s7ijKIRYvKfutFoHdVdqletfd2J6z4ex0Y6f+i9ZcNQknZz7fpJO1lKhA 6NdhV2kPq4/rE4LYeQDDJX3HpuMYlEKp5+vzgzPgj++bCpeUSw3fykWmRQLPv0bJYJs+ 6WCw== X-Gm-Message-State: AOAM5324wy4Twehw3WaewiD0+9zBQ99X993LCbC9DulIJm7MizJpmDr9 G4VwbRzB1QZ0n66UOV4aIOxtMnGhlEM= X-Google-Smtp-Source: ABdhPJw9+rQ072m4P/FyBhSZyguKMXKdAuqeVSaF4cMQeqv/OjPIBkgv2G5hNxq6JfSmJ1UF1I2U1w== X-Received: by 2002:a17:902:d2ce:b029:eb:364:a2a0 with SMTP id n14-20020a170902d2ceb02900eb0364a2a0mr28080950plc.0.1618910400679; Tue, 20 Apr 2021 02:20:00 -0700 (PDT) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id k15sm15247630pfi.0.2021.04.20.02.19.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Apr 2021 02:20:00 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Junio C Hamano Subject: [PATCH 1/5] git-completion.bash: separate some commands onto their own line Date: Tue, 20 Apr 2021 02:19:47 -0700 Message-Id: <65c485ea0c1726c96d292d7d7385def8d2f19f25.1618910364.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.31.1.424.g95a8dafae5 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In e94fb44042 (git-completion.bash: pass $__git_subcommand_idx from __git_main(), 2021-03-24), a line was introduced which contained multiple statements. This is difficult to read so break it into multiple lines. While we're at it, follow this convention for the rest of the __git_main() and break up lines that contain multiple statements. Signed-off-by: Denton Liu --- contrib/completion/git-completion.bash | 37 +++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index c926ca26c6..1dedb14b47 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3400,17 +3400,35 @@ __git_main () while [ $c -lt $cword ]; do i="${words[c]}" case "$i" in - --git-dir=*) __git_dir="${i#--git-dir=}" ;; - --git-dir) ((c++)) ; __git_dir="${words[c]}" ;; - --bare) __git_dir="." ;; - --help) command="help"; break ;; - -c|--work-tree|--namespace) ((c++)) ;; - -C) __git_C_args[C_args_count++]=-C + --git-dir=*) + __git_dir="${i#--git-dir=}" + ;; + --git-dir) + ((c++)) + __git_dir="${words[c]}" + ;; + --bare) + __git_dir="." + ;; + --help) + command="help" + break + ;; + -c|--work-tree|--namespace) + ((c++)) + ;; + -C) + __git_C_args[C_args_count++]=-C ((c++)) __git_C_args[C_args_count++]="${words[c]}" ;; - -*) ;; - *) command="$i"; __git_subcommand_idx="$c"; break ;; + -*) + ;; + *) + command="$i" + __git_subcommand_idx="$c" + break + ;; esac ((c++)) done @@ -3432,7 +3450,8 @@ __git_main () ;; esac case "$cur" in - --*) __gitcomp " + --*) + __gitcomp " --paginate --no-pager --git-dir= From patchwork Tue Apr 20 09:19:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 12213593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BE22C433B4 for ; Tue, 20 Apr 2021 09:20:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6075D61363 for ; Tue, 20 Apr 2021 09:20:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231371AbhDTJUi (ORCPT ); Tue, 20 Apr 2021 05:20:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231316AbhDTJUd (ORCPT ); Tue, 20 Apr 2021 05:20:33 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64D58C06138A for ; Tue, 20 Apr 2021 02:20:02 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id 31so10688178pgn.13 for ; Tue, 20 Apr 2021 02:20:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Oz9EgYl8lU1Gaw389Uq8GHGSxK5HGbLF0V3e4S6MBaA=; b=R0hqHYtyhXsR+HHqMpBZaKCpdqDBagdFoiJ9E1zq5W8Z4EZJhnncVOFLJoWJnyP94r gfIhkQPBIN7e+ydCr8MdRqJOF8+C+I7I5lzQWBABPVdE9dr/QO/dV1U0w32qzIi/84uh fKJ4KVfeMxzYX+ZyT9aJ6a8LUYAXqEp+YRIPbv5Sky63v1qnXuCh4ZyleZZ8WJUwZ3vX dvu+QXh578Nok2AyffuGYhBtls9l2J5Wsfu58Mz8bJW15My/Y0vOPAOWD0KV0A2rWOXa bfiu5g2Xa8X7wG6A/aPNVAAN7Gs0UgoXeHTkROY7KqKPO09d/8YLuxVdF2SgPDkQjmVX Jqew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Oz9EgYl8lU1Gaw389Uq8GHGSxK5HGbLF0V3e4S6MBaA=; b=syAPY8pe+t9zGRJ1LUmUZu5fDeS6t8vewyl5CxUyA/DRoJoSgcJm3/HEYTupCRSev/ 6AsT3hz3b+gn3z0qaw2NMKTCGGsTeLGH0iewTqKPxB0Lb1qVj5Kkvssdxwj9PslluDNp uIj5WNDJHl7nG9cLbyE/KdD5YSaMhUt0Efw1wRTmJLa37jEzltuGhlQ9u2HvfARr1IzX 9/BCP9pew1g4Bf1MFbo77yS7xaEFzWy222O1860JPqVMn5Js7Zopqddr5TzOjebcUqv7 m1e/1/teXmf003HKhxTywHLqX/9sn5ej/skPj3mX2Y1HMkfWT5gR5ch2QKUSMwgxQxxP x30w== X-Gm-Message-State: AOAM530kOjKfNKhlLwOm4/yDduSElTeqHVqyQZiXUBxeUkN0hnBYA3mf hgP+IPlg4WsQMXSn0SgOi1ZgIqSWsn4= X-Google-Smtp-Source: ABdhPJz5tUF2hm6/L24PWMaGJYnS+c4BH+uGaZgzIP/kil7tr/6By8jooHzLvN30A0QmIJE6QcpN5Q== X-Received: by 2002:a63:1b10:: with SMTP id b16mr15764978pgb.308.1618910401618; Tue, 20 Apr 2021 02:20:01 -0700 (PDT) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id k15sm15247630pfi.0.2021.04.20.02.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Apr 2021 02:20:01 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Junio C Hamano Subject: [PATCH 2/5] git-completion.bash: rename to $__git_cmd_idx Date: Tue, 20 Apr 2021 02:19:48 -0700 Message-Id: <7c7d6de380d1aaa860e86627778bef6c0c78ca08.1618910364.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.31.1.424.g95a8dafae5 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In e94fb44042 (git-completion.bash: pass $__git_subcommand_idx from __git_main(), 2021-03-24), the $__git_subcommand_idx variable was introduced. Naming it after the index of the subcommand is flat-out wrong as this variable really holds the index of the git comand (e.g. "stash"). Rename this variable so that it's obvious it's about git commands. While we're at it, shorten up its name so that it's still readable without being a handful to type. Signed-off-by: Denton Liu --- contrib/completion/git-completion.bash | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 1dedb14b47..c29c129f87 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1474,12 +1474,12 @@ _git_branch () _git_bundle () { - local cmd="${words[__git_subcommand_idx+1]}" + local cmd="${words[__git_cmd_idx+1]}" case "$cword" in - $((__git_subcommand_idx+1))) + $((__git_cmd_idx+1))) __gitcomp "create list-heads verify unbundle" ;; - $((__git_subcommand_idx+2))) + $((__git_cmd_idx+2))) # looking for a file ;; *) @@ -1894,7 +1894,7 @@ _git_grep () esac case "$cword,$prev" in - $((__git_subcommand_idx+1)),*|*,-*) + $((__git_cmd_idx+1)),*|*,-*) __git_complete_symbol && return ;; esac @@ -3017,7 +3017,7 @@ _git_stash () local subcommand="$(__git_find_on_cmdline "$subcommands save")" if [ -z "$subcommand" ]; then - case "$((cword - __git_subcommand_idx)),$cur" in + case "$((cword - __git_cmd_idx)),$cur" in *,--*) __gitcomp_builtin stash_push ;; @@ -3058,7 +3058,7 @@ _git_stash () __gitcomp_builtin stash_branch ;; branch,*) - if [ $cword -eq $((__git_subcommand_idx+2)) ]; then + if [ $cword -eq $((__git_cmd_idx+2)) ]; then __git_complete_refs else __gitcomp_nl "$(__git stash list \ @@ -3303,7 +3303,7 @@ _git_worktree () # be either the 'add' subcommand, the unstuck # argument of an option (e.g. branch for -b|-B), or # the path for the new worktree. - if [ $cword -eq $((__git_subcommand_idx+2)) ]; then + if [ $cword -eq $((__git_cmd_idx+2)) ]; then # Right after the 'add' subcommand: have to # complete the path, so fall back to Bash # filename completion. @@ -3327,7 +3327,7 @@ _git_worktree () __git_complete_worktree_paths ;; move,*) - if [ $cword -eq $((__git_subcommand_idx+2)) ]; then + if [ $cword -eq $((__git_cmd_idx+2)) ]; then # The first parameter must be an existing working # tree to be moved. __git_complete_worktree_paths @@ -3395,7 +3395,7 @@ __git_main () { local i c=1 command __git_dir __git_repo_path local __git_C_args C_args_count=0 - local __git_subcommand_idx + local __git_cmd_idx while [ $c -lt $cword ]; do i="${words[c]}" @@ -3426,7 +3426,7 @@ __git_main () ;; *) command="$i" - __git_subcommand_idx="$c" + __git_cmd_idx="$c" break ;; esac From patchwork Tue Apr 20 09:19:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 12213595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24E2BC43461 for ; Tue, 20 Apr 2021 09:20:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA368613AB for ; Tue, 20 Apr 2021 09:20:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231382AbhDTJUj (ORCPT ); Tue, 20 Apr 2021 05:20:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231325AbhDTJUe (ORCPT ); Tue, 20 Apr 2021 05:20:34 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F39DC06138B for ; Tue, 20 Apr 2021 02:20:03 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id i190so25111983pfc.12 for ; Tue, 20 Apr 2021 02:20:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pu4tlybI35Z02KrsPO3c4r9zx4I/I0vuQpsUd5WaJ2E=; b=Mh+3KuXkFjDh5sPUZeUPUmwwlYGKl4Qw1h5W23WKzA4/B38YBfIj2QqgXiBnELm+Xa kSj86jP9+igfOFLdtda6NwgvzoJOmVJKpaA3zA7MXHDjRnGQ3/AaVxiuqQFZlEJTK3QC DjK/MbZZzd47A+dqPeAeza7zEZ2dcF23SthxRqNC95LOJ9R/+cGtSKeB2noX2aiPN33c +PaIRv5tAiRk2vAcVRTm+1wi3Om6/rWr/du/3ODVZXECSDHgV23hcu7qSbDa3TUhr6HL 31KVw9+DpxrzjhY54xz8+j5wc5vtP0kYhq7Km5xD5GqFT+OnnmhkUB5D+5T8KkXv1uBR rz5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Pu4tlybI35Z02KrsPO3c4r9zx4I/I0vuQpsUd5WaJ2E=; b=YpY3VPPqdiIQ724FTASvY3ZjGwLREdno1aHqQYEWM/UK7bSt12YKxAFBzEFr07M7ch ofeEjjgWc/pu+n1zJ579uyw14bVSUYpuT6kJ8tlDaE0dCzCw955i9tXcvU3Qa8b3Uddc KDzBay8fb6Zkj8Xs9ul2jfCgeLPUywJMQDqEsUQoDCVSvaQkfj5GI052qZclvwpmLeyn X3KKA9J0DCQCUUqxwAYbqbtciyjrmr+eMIio29w4itH8tWHZ/DlUpKyLl7cdNZrBrhmr uAtdYSvzk5hrt/LknAw+QlUyroLZcEMyCf7bp+9mh23ZM1HhKswer4ShLhvvi/Ddccat X7VA== X-Gm-Message-State: AOAM5300tuv9kG3IkQLL/uoOPC01J2MmUhsdLWNlDHohSKdVvsHGWaxS 6rP5eSmp3xmfVymHbK7WQ+yXNUH6atk= X-Google-Smtp-Source: ABdhPJy8RKYHTBq7KbtsZODv0VpByuqIia2+Apw5/Bmh2ZM2cbHmhf7iz/JA/T3eG6zbrDtUYfy8pw== X-Received: by 2002:a63:2e47:: with SMTP id u68mr16121670pgu.6.1618910402662; Tue, 20 Apr 2021 02:20:02 -0700 (PDT) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id k15sm15247630pfi.0.2021.04.20.02.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Apr 2021 02:20:02 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Junio C Hamano Subject: [PATCH 3/5] git-completion.bash: use $__git_cmd_idx in more places Date: Tue, 20 Apr 2021 02:19:49 -0700 Message-Id: <63a699258545d55e47d9f6fcf6e70055a76e8949.1618910364.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.31.1.424.g95a8dafae5 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org With the introduction of the $__git_cmd_idx variable in e94fb44042 (git-completion.bash: pass $__git_subcommand_idx from __git_main(), 2021-03-24), completion functions were able to know the index at which the git command is listed, allowing them to skip options that are given to the underlying git itself, not the corresponding command (e.g. `-C asdf` in `git -C asdf branch`). While most of the changes here are self-explanatory, some bear further explanation. For the __git_find_on_cmdline() and __git_find_last_on_cmdline() pair of functions, these functions are only ever called in the context of a git command completion function. These functions will only care about words after the command so we can safely ignore the words before this. For _git_worktree(), this change is technically a no-op (once the __git_find_last_on_cmdline change is also applied). It was in poor style to have hard-coded on the index right after `worktree`. In case `git worktree` were to ever learn to accept options, the current situation would be inflexible. Signed-off-by: Denton Liu --- contrib/completion/git-completion.bash | 26 ++++++++++++++------------ t/t9902-completion.sh | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index c29c129f87..30c9a97616 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1006,8 +1006,8 @@ __git_complete_revlist () __git_complete_remote_or_refspec () { - local cur_="$cur" cmd="${words[1]}" - local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0 + local cur_="$cur" cmd="${words[__git_cmd_idx]}" + local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0 if [ "$cmd" = "remote" ]; then ((c++)) fi @@ -1176,7 +1176,7 @@ __git_aliased_command () # --show-idx: Optionally show the index of the found word in the $words array. __git_find_on_cmdline () { - local word c=1 show_idx + local word c="$__git_cmd_idx" show_idx while test $# -gt 1; do case "$1" in @@ -1221,7 +1221,7 @@ __git_find_last_on_cmdline () done local wordlist="$1" - while [ $c -gt 1 ]; do + while [ $c -gt "$__git_cmd_idx" ]; do ((c--)) for word in $wordlist; do if [ "$word" = "${words[c]}" ]; then @@ -1306,7 +1306,7 @@ __git_count_arguments () local word i c=0 # Skip "git" (first argument) - for ((i=1; i < ${#words[@]}; i++)); do + for ((i="$__git_cmd_idx"; i < ${#words[@]}; i++)); do word="${words[i]}" case "$word" in @@ -1442,7 +1442,7 @@ __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD _git_branch () { - local i c=1 only_local_ref="n" has_r="n" + local i c="$__git_cmd_idx" only_local_ref="n" has_r="n" while [ $c -lt $cword ]; do i="${words[c]}" @@ -2474,7 +2474,7 @@ _git_switch () __git_config_get_set_variables () { local prevword word config_file= c=$cword - while [ $c -gt 1 ]; do + while [ $c -gt "$__git_cmd_idx" ]; do word="${words[c]}" case "$word" in --system|--global|--local|--file=*) @@ -3224,7 +3224,7 @@ _git_svn () _git_tag () { - local i c=1 f=0 + local i c="$__git_cmd_idx" f=0 while [ $c -lt $cword ]; do i="${words[c]}" case "$i" in @@ -3276,9 +3276,11 @@ __git_complete_worktree_paths () _git_worktree () { local subcommands="add list lock move prune remove unlock" - local subcommand + local subcommand subcommand_idx - subcommand="$(__git_find_on_cmdline "$subcommands")" + subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")" + subcommand_idx="${subcommand% *}" + subcommand="${subcommand#* }" case "$subcommand,$cur" in ,*) @@ -3303,7 +3305,7 @@ _git_worktree () # be either the 'add' subcommand, the unstuck # argument of an option (e.g. branch for -b|-B), or # the path for the new worktree. - if [ $cword -eq $((__git_cmd_idx+2)) ]; then + if [ $cword -eq $((subcommand_idx+1)) ]; then # Right after the 'add' subcommand: have to # complete the path, so fall back to Bash # filename completion. @@ -3327,7 +3329,7 @@ _git_worktree () __git_complete_worktree_paths ;; move,*) - if [ $cword -eq $((__git_cmd_idx+2)) ]; then + if [ $cword -eq $((subcommand_idx+1)) ]; then # The first parameter must be an existing working # tree to be moved. __git_complete_worktree_paths diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 04ce884ef5..9439fec8f0 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1879,6 +1879,7 @@ test_expect_success '__git_find_on_cmdline - single match' ' ( words=(git command --opt list) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline "add list remove" >actual ) && test_cmp expect actual @@ -1889,6 +1890,7 @@ test_expect_success '__git_find_on_cmdline - multiple matches' ' ( words=(git command -o --opt remove list add) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline "add list remove" >actual ) && test_cmp expect actual @@ -1898,6 +1900,7 @@ test_expect_success '__git_find_on_cmdline - no match' ' ( words=(git command --opt branch) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline "add list remove" >actual ) && test_must_be_empty actual @@ -1908,6 +1911,7 @@ test_expect_success '__git_find_on_cmdline - single match with index' ' ( words=(git command --opt list) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline --show-idx "add list remove" >actual ) && test_cmp expect actual @@ -1918,6 +1922,7 @@ test_expect_success '__git_find_on_cmdline - multiple matches with index' ' ( words=(git command -o --opt remove list add) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline --show-idx "add list remove" >actual ) && test_cmp expect actual @@ -1927,11 +1932,23 @@ test_expect_success '__git_find_on_cmdline - no match with index' ' ( words=(git command --opt branch) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline --show-idx "add list remove" >actual ) && test_must_be_empty actual ' +test_expect_success '__git_find_on_cmdline - ignores matches before command with index' ' + echo "6 remove" >expect && + ( + words=(git -C remove command -o --opt remove list add) && + cword=${#words[@]} && + __git_cmd_idx=3 && + __git_find_on_cmdline --show-idx "add list remove" >actual + ) && + test_cmp expect actual +' + test_expect_success '__git_get_config_variables' ' cat >expect <<-EOF && name-1 @@ -2275,6 +2292,7 @@ do ( words=(git push '$flag' other ma) && cword=${#words[@]} cur=${words[cword-1]} && + __git_cmd_idx=1 && __git_complete_remote_or_refspec && print_comp ) && @@ -2288,6 +2306,7 @@ do ( words=(git push other '$flag' ma) && cword=${#words[@]} cur=${words[cword-1]} && + __git_cmd_idx=1 && __git_complete_remote_or_refspec && print_comp ) && From patchwork Tue Apr 20 09:19:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 12213597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD626C43462 for ; Tue, 20 Apr 2021 09:20:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 97AA561363 for ; Tue, 20 Apr 2021 09:20:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231410AbhDTJUj (ORCPT ); Tue, 20 Apr 2021 05:20:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230090AbhDTJUf (ORCPT ); Tue, 20 Apr 2021 05:20:35 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43864C06138C for ; Tue, 20 Apr 2021 02:20:04 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id 20so15393594pll.7 for ; Tue, 20 Apr 2021 02:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bMr5RwWvz1Wjmmk/xiGkhzAWg4eR4Q1W8mE6K97pmjg=; b=N3t4j7PC9U44dhvlYHfWsJgbpTou9i4JprRZiOEPxDv3c8vVjiQNO7A9cvfNRqFZSg R5zksPGDV2HoP+eMqTePdDq+4w2g8K7YTZNQkg0V1ROsDtjEi/WbZaRNB/iimlXtqhKq olZkBjqd7gaujiTXvNmwHiN/FBU8uA+GpOJMKesWzeOKwCrREkXc2ogIR1twcM6+Netq lFvg/fTHBVjgSirmo/bYfkcHORlRIOkCY3gJfAPehDbYlMrTzGsOhieCp+f+G29Kw1AE 8mYAvRvZWkZwg2nLKalxDjbRucctHo/SqqCV+sBYdI+rFf4xJ1PbeB6T9H49IrDYeDcq k/OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bMr5RwWvz1Wjmmk/xiGkhzAWg4eR4Q1W8mE6K97pmjg=; b=Fpb2Duxbcs1T2mqppLB7RzH8xOlaJmiSSS7j0ebgPLpCosLMUQPf2vKBUzYo+bUHmY fuNSWCKnj1h0zMwjbUJVzxkP7NzcL7eCMNBwvXPiorSPGjg4T2mNHFlF8olZLLmrEp7q +uBhbtwESRO7TX7QSpk75HlRCONOjZSfQmxuUWCmYfXUWKQuB34mq/BPSVyXOkiom5wb FRD/VLgUnzWCEDNMjYjARkeDoy0aPtwfjd3w8dqUcMuYs4LbNDXooquafQ/ELoOy9OV9 xQSLnU8M1T1tgdXfrDBD/1oFFMWaaMU1DLkE97SsCYPdzuuwXrlvLTyr3bMkgUdFUyc1 UzcA== X-Gm-Message-State: AOAM532OVxoh8jv+w3Uw/I3rvHAFlfzPcaTfIzIaIuKqHCiBM70kOb2u fMA5aw8mKD9s6ZPFsLyxJNCnoq7nNVs= X-Google-Smtp-Source: ABdhPJxExJ6glxHJM/gKXWIRJ0OxQ5H4IKmk+B7V2jSBIYRCJnDjj/YV2lS2y7RmR+biQxNf7acH2Q== X-Received: by 2002:a17:902:ac89:b029:e6:d199:29ac with SMTP id h9-20020a170902ac89b02900e6d19929acmr27864120plr.46.1618910403626; Tue, 20 Apr 2021 02:20:03 -0700 (PDT) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id k15sm15247630pfi.0.2021.04.20.02.20.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Apr 2021 02:20:03 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Junio C Hamano Subject: [PATCH 4/5] git-completion.bash: consolidate cases in _git_stash() Date: Tue, 20 Apr 2021 02:19:50 -0700 Message-Id: <4f8d015d54376af277883f57e8b4cf2c63ed8a03.1618910364.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.31.1.424.g95a8dafae5 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The $subcommand case statement in _git_stash() is quite repetitive. Consolidate the cases together into one catch-all case to reduce the repetition. Signed-off-by: Denton Liu --- contrib/completion/git-completion.bash | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 30c9a97616..7bce9a0112 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3032,21 +3032,6 @@ _git_stash () fi case "$subcommand,$cur" in - push,--*) - __gitcomp_builtin stash_push - ;; - save,--*) - __gitcomp_builtin stash_save - ;; - pop,--*) - __gitcomp_builtin stash_pop - ;; - apply,--*) - __gitcomp_builtin stash_apply - ;; - drop,--*) - __gitcomp_builtin stash_drop - ;; list,--*) # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show() __gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options" @@ -3054,8 +3039,8 @@ _git_stash () show,--*) __gitcomp_builtin stash_show "$__git_diff_common_options" ;; - branch,--*) - __gitcomp_builtin stash_branch + *,--*) + __gitcomp_builtin "stash_$subcommand" ;; branch,*) if [ $cword -eq $((__git_cmd_idx+2)) ]; then @@ -3069,8 +3054,6 @@ _git_stash () __gitcomp_nl "$(__git stash list \ | sed -n -e 's/:.*//p')" ;; - *) - ;; esac } From patchwork Tue Apr 20 09:19:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 12213599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19AA2C433B4 for ; Tue, 20 Apr 2021 09:20:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA60661363 for ; Tue, 20 Apr 2021 09:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231325AbhDTJUk (ORCPT ); Tue, 20 Apr 2021 05:20:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231364AbhDTJUh (ORCPT ); Tue, 20 Apr 2021 05:20:37 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 507B8C06138E for ; Tue, 20 Apr 2021 02:20:05 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id s14so14664814pjl.5 for ; Tue, 20 Apr 2021 02:20:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XEXzjTAV9dXOUikle5rOylao5pimN+EO1ck4FrWSz3c=; b=n33ZyWtLzRZ9P3EHBFBWuR4l17ZxTdiI3stfzsXJHmPnY8fxH5M+dvSD89ifcB+GUr cAnfBuuGsq5TC7C8KFN9T2QliOoOGNTh/2n1gG2e9rTthfhayWiakJ6apz5VWn0umyX9 3R8tIccfzMJMV0KKBCgI3D0zVmM2/zm82bZlzgBKhotywf9/56CBVbELPouJD63Avapv RbiSwoI19R4fnpvEOpAwB3+7M9mTR3wFaK3+n3WQSr7eDIO1WL5SUhrfI7wjcN7J2sha m+YUhMCA6Omb6PpuiT5b4zMjinR3WlI3RikQBKZsUg4OjteG40O2JN++qCdhN2/5dMGv RhDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XEXzjTAV9dXOUikle5rOylao5pimN+EO1ck4FrWSz3c=; b=kxbKGzwVBTZDcLA4kqK3U0ht9ytD3k5v/Z8g2i9Ueu0dLl/3Kqb5vMea7kuYwPhThu zk9W0rTExOHKl1JnlXoclQGDLfaBSRnEwJymPriERFp8WjWZpSpLGbqrfhbl7Vmvz+SU iHwPLYqqY/Rltol+o1Oa3lijGPeaL6VkT+Nl4zYIr2p+z4HjiTgmP5RRF5jF9nXwHmKW Iz0uM91k1ykXNdmDaGBSWZfsVCSFyloqQ2BYuSO+tkHWP2v9/kD8hc2yWNQsif99r7L8 tzRRPD4fAFMJU1fZVcsiNx/uKqWhOueUIQpKRcL+umAaagod7UWv99NdMgl2r8QpaFc6 DYhw== X-Gm-Message-State: AOAM533caC+noIfS8eY0twbayJG68ZZqNUYcWK126H7o+iRL1IE6/Rdm 8AA2wLjEOX3LYgAz55f+8P+wNfWfKFI= X-Google-Smtp-Source: ABdhPJzuY8K5aSAN9gpP74D6gjWVNV9DPioExvmMGwljiPq0+M78ZyPJe3ZNbHcDwgTFbsPVZibnKw== X-Received: by 2002:a17:90a:5885:: with SMTP id j5mr3941298pji.102.1618910404671; Tue, 20 Apr 2021 02:20:04 -0700 (PDT) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id k15sm15247630pfi.0.2021.04.20.02.20.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Apr 2021 02:20:04 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Junio C Hamano Subject: [PATCH 5/5] git-completion.bash: consolidate no-subcommand case for _git_stash() Date: Tue, 20 Apr 2021 02:19:51 -0700 Message-Id: X-Mailer: git-send-email 2.31.1.424.g95a8dafae5 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We have a separate if case for when no subcommand is given. It is simpler to just consolidate this logic into the case statement below. It would be nice to complete remove the magic that deals with indices and replace it with what was originally there, if [ -z "$subcommand" -a -n "$(__git_find_on_cmdline "-p")" ]; then subcommand="push" fi but this gives a slightly incorrect completion. In the case where we're attempting to complete `git stash -a ` we will get the subcommands back as a respose instead of the completions for `git stash push`, which is what we'd expect. We could potentially hardcode all of the short options but that would be too much work to maintain so we stick with the index solution. Signed-off-by: Denton Liu --- contrib/completion/git-completion.bash | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 7bce9a0112..060adc0ed7 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3016,22 +3016,22 @@ _git_stash () local subcommands='push list show apply clear drop pop create branch' local subcommand="$(__git_find_on_cmdline "$subcommands save")" - if [ -z "$subcommand" ]; then - case "$((cword - __git_cmd_idx)),$cur" in - *,--*) - __gitcomp_builtin stash_push - ;; - 1,sa*) - __gitcomp "save" - ;; - 1,*) - __gitcomp "$subcommands" - ;; - esac - return - fi - case "$subcommand,$cur" in + ,--*) + __gitcomp_builtin stash_save + ;; + ,sa*) + __git_init_builtin_opts stash_save + if ((cword - __git_cmd_idx == 1)); then + __gitcomp "save" + fi + ;; + ,*) + __git_init_builtin_opts stash_save + if ((cword - __git_cmd_idx == 1)); then + __gitcomp "$subcommands" + fi + ;; list,--*) # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show() __gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options"